0x933eb0bb, 0x97ffad0c, 0xafb010b1, 0xab710d06, 0xa6322bdf, 0xa2f33668,
0xbcb4666d, 0xb8757bda, 0xb5365d03, 0xb1f740b4 };
+StreamInfo::StreamInfo(byte* data, int index)throw(std::invalid_argument)
+{
+ if (NULL == data) {
+ throw std::invalid_argument("stream data is null");
+ }
+
+ if (std::strlen(data) + index < 5) {
+ throw std::invalid_argument("stream data too short");
+ }
+
+ uint descLength = (uint)((data[3 + index] & 0x0f) << 8) + data[4 + index];
+
+ if (descLength > Constants::TS_SIZE) {
+ throw std::invalid_argument("descriptors data too long");
+ }
+
+ if (5 + descLength > std::strlen(data) - index) {
+ throw std::invalid_argument("stream data too short");
+ }
+
+ mData = new byte[5 + descLength];
+ for (int i = 0; i < sizeof(mData); i++) {
+ mData[i] = data[i + index];
+ }
+
+ mVideoFormat = SetVideoFormat(VideoFormat::VF_Reserved);
+ mAspectRatio = SetAspectRatio(AR_Reserved);
+ mFrameRate = SetFrameRate(FR_Reserved);
+ mAudioPresentationType = SetAudioPresentationType(AP_Reserved);
+ mSamplingFrequency = SetSamplingFrequency(SF_Reserved);
+}
+
+VideoFormat StreamInfo::GetVideoFormat(void)
+{
+ return mVideoFormat;
+}
+
+void StreamInfo::SetVideoFormat(VideoFormat video_format)
+{
+ mVideoFormat = video_format;
+}
+
+AspectRatio StreamInfo::GetAspectRatio(void)
+{
+ return mAspectRatio;
+}
+
+void StreamInfo::SetAspectRatio(AspectRatio aspect_ratio)
+{
+ mAspectRatio = aspect_ratio;
+}
+
+FrameRate StreamInfo::GetFrameRate(void)
+{
+ return mFrameRate;
+}
+
+void StreamInfo::FrameRate(FrameRate frame_rate)
+{
+ mFrameRate = frame_rate;
+}
+
+AudioPresentationType StreamInfo::GetAudioPresentationType(void)
+{
+ return mAudioPresentationType;
+}
+
+void StreamInfo::SetAudioPresentationType(AudioPresentationType ap_type)
+{
+ mAudioPresentationType = ap_type;
+}
+
+SamplingFrequency StreamInfo::GetSamplingFrequency(void)
+{
+ return mSamplingFrequency;
+}
+
+StreamInfo::SetSamplingFrequency(SamplingFrequency sampling_frequency)
+{
+ mSamplingFrequency = sampling_frequency;
+}
+
+StreamInfo::StreamInfo(ElementaryStreamTypes streamType, ushort elementaryPid)
+{
+ mData = new byte[5];
+ StreamType = streamType;
+ ElementaryPID = elementaryPid;
+ // reserved and descriptors length
+ mData[3] = 0xf0;
+ mData[4] = 0x00;
+}
+
+byte* StreamInfo::GetByteData(void)
+{
+ return mData;
+}
+
+StreamType StreamInfo::GetElementaryStreamTypes(void)
+{
+ return (ElementaryStreamTypes)mData[0];
+}
+
+void StreamInfo::SetElementaryStreamTypes(StreamType stream_type)
+{
+ mData[0] = (byte)stream_type;
+}
+ushort StreamInfo::GetElementaryPID(void)
+{
+ return (ushort)(((mData[1] & 0x1f) << 8) + mData[2]);
+}
+
+void StreamInfo::GetElementaryPID(ushort pid)
+{
+ mData[1] = (byte)(((pid >> 8) & 0x1f) | 0xe0);
+ mData[2] = (byte)(pid & 0xff);
+}
+
+byte* StreamInfo::GetElementaryDescriptors(void)
+{
+ if (std::strlen(mData) == 5) return null;
+ byte* descriptors = new byte[mData.Length - 5];
+ for (int i = 0; i < sizeof(descriptors); i++)
+ {
+ descriptors[i] = mData[i + 5];
+ }
+ return descriptors;
+}
+
+void StreamInfo::SetElementaryDescriptors(byte* value)
+{
+ if(null == value || 0 == sizeof(value))
+ {
+ if(mData.Length > 5)
+ {
+ // need to remove existing descriptors
+ byte[] data = new byte[5];
+ data[0] = mData[0];
+ data[1] = mData[1];
+ data[2] = mData[2];
+ data[3] = 0xf0;
+ data[4] = 0x00;
+ mData = data;
+ }
+ else
+ {
+ // nothing to do
+ return;
+ }
+ }
+ else
+ {
+ if(sizeof(value) > 180) {
+ throw new ArgumentException("descriptors data too long");
+ }
+
+ byte* data = new byte[5 + value.Length];
+ data[0] = mData[0];
+ data[1] = mData[1];
+ data[2] = mData[2];
+ data[3] = (byte)(0xf0 | (byte)((value.Length >> 8) & 0x0f));
+ data[4] = (byte)(value.Length & 0xff);
+ for (int i = 0; i < value.Length; i++)
+ {
+ data[5 + i] = value[i];
+ }
+ mData = data;
+ }
+}
+
#include <string>
#include <list>
+#include <stdexcept>
// #include "BlueMux.h"
#include "tsremuxcpp_define.h"
class StreamInfo {
public:
- StreamInfo(byte* data, int index);
+ StreamInfo(byte* data, int index)throw(std::invalid_argument);
VideoFormat GetVideoFormati(void);
void SetVideoFormat(VideoFormat videoformat);
AspectRatio GetAspectRatio(void);
SamplingFrequency GetsamplingFrequency(void);
void SetSamplingFrequency(SamplingFrequency samplingFrequency);
StreamInfo(ElementaryStreamTypes streamType, ushort elementaryPid);
- byte* Data;
- ElementaryStreamTypes StreamType;
- ushort ElementaryPID;
+ byte* GetByteData(void);
byte* ElementaryDescriptors;
private:
byte* mData;
FrameRate mFrameRate;
AudioPresentationType mAudioPresentationType;
SamplingFrequency mSamplingFrequency;
+ ElementaryStreamTypes StreamType;
+ ushort ElementaryPID;
};
class BluRayOutput {