Beispiel #1
0
            /// <summary>
            /// ReadQMed
            /// Read different types of QMed.
            /// Side-effects: sets qmed and privateCodecData vars.
            /// </summary>
            /// <param name="br">BinaryReader</param>
            /// <param name="sampleStreamType"></param>
            /// <param name="inTotalSize"></param>
            private void ReadQMed(BinaryReader br, ushort sampleStreamType, int inTotalSize, ulong sampleFlags)
            {
                long byteCount = 0;
                switch ((uint)sampleStreamType)
                {
                  case QBOX_SAMPLE_TYPE_AAC:
                QMed.QMedAAC qmedaac = new QMed.QMedAAC();
                qmedaac.payloadSize = inTotalSize - mSampleHeaderSize;
                #if ADTS
                qmedaac.Read(br, cts);
                #endif
                qmed = qmedaac;
                break;
                  //case QBOX_SAMPLE_TYPE_H264:
                  //case QBOX_SAMPLE_TYPE_H264_SLICE:
                  //  QMed.QMedH264 qmedh264 = new QMed.QMedH264();
                  //  qmed = qmedh264;
                  //  break;
                  case QBOX_SAMPLE_TYPE_QPCM:
                QMed.QMedPCM qmedpcm = new QMed.QMedPCM();
                qmed = qmedpcm;
                break;
                  case QBOX_SAMPLE_TYPE_Q711:
                QMed.QMed711 qmed711 = new QMed.QMed711();
                qmed = qmed711;
                break;
                  case QBOX_SAMPLE_TYPE_Q722:
                QMed.QMed722 qmed722 = new QMed.QMed722();
                qmed = qmed722;
                break;
                  case QBOX_SAMPLE_TYPE_Q726:
                QMed.QMed726 qmed726 = new QMed.QMed726();
                qmed = qmed726;
                break;
                  case QBOX_SAMPLE_TYPE_Q728:
                QMed.QMed728 qmed728 = new QMed.QMed728();
                qmed = qmed728;
                break;
                  case QBOX_SAMPLE_TYPE_JPEG:
                // unknown 12-byte jpeg prefix
                byte[] unknown = new byte[12];
                br.Read(unknown, 0, 12);
                QMed.QMedJpeg qmedJpeg = new QMed.QMedJpeg();
                qmed = qmedJpeg;
                break;
                  case QBOX_SAMPLE_TYPE_MPEG2_ELEMENTARY:
                  case QBOX_SAMPLE_TYPE_USER_METADATA:
                  case QBOX_SAMPLE_TYPE_QMA:
                  case QBOX_SAMPLE_TYPE_DEBUG:
                  case QBOX_SAMPLE_TYPE_VIN_STATS_GLOBAL:
                  case QBOX_SAMPLE_TYPE_VIN_STATS_MB:
                break;
                  default:
                throw new Exception(string.Format("Unexpected QBox type: {0}", sampleStreamType));
                }

                int count;
                #if ADTS
                if (qmed.GetType() != typeof(QMed.QMedAAC))
                 count = qmed.Read(br);
                #else
                count = qmed.Read(br);
                #endif
                if (count != (int)qmed.boxSize)
                  throw new Exception("QMed header count inconsistent");

                mSampleHeaderSize += (int)qmed.boxSize;

                byteCount = inTotalSize - count;

                if (byteCount < 0)
                  throw new Exception("QMed read: bad box size");

                if (byteCount > 0)
                {
                  // read-in data; set mPayload, except when it's a config box
                  if ((sampleFlags & QBOX_SAMPLE_FLAGS_CONFIGURATION_INFO) != 0)
                  {
                // get private codec data
                privateCodecData = br.ReadBytes((int)byteCount);
                mSampleHeaderSize += (int)byteCount;
                byteCount = 0;
                  }
                  else // read payload now
                  {
                mPayload = br.ReadBytes((int)byteCount);
                  }
                }
            }
Beispiel #2
0
 public QBoxSample(int dataSize, ulong sampleFlags, ushort sampleStreamType)
 {
     if ((sampleFlags & QBox.QBOX_SAMPLE_FLAGS_META_INFO) != 0)
     {
       if (sampleStreamType == QBox.QBOX_SAMPLE_TYPE_H264)
       {
     if (v != null)
       throw new Exception("QBoxSample.constructor: QBoxMetaV v already set");
     v = new QBoxMetaV();
     mSampleHeaderSize = 32;
       }
       else if ((sampleStreamType == QBox.QBOX_SAMPLE_TYPE_QMA) || (sampleStreamType == QBox.QBOX_SAMPLE_TYPE_AAC))
       {
     if (a != null)
       throw new Exception("There should only be one QBoxMetaA for audio");
     a = new QBoxMetaA();
     mSampleHeaderSize = 24;
       }
       else throw new Exception("QBoxSample.Read: Sample stream type not found.");
     }
     else if ((sampleFlags & QBox.QBOX_SAMPLE_FLAGS_QMED_PRESENT) > 0)
     {
       switch ((uint)sampleStreamType)
       {
     case QBOX_SAMPLE_TYPE_AAC:
       QMed.QMedAAC qmedaac = new QMed.QMedAAC();
       qmed = qmedaac;
       break;
     //case QBOX_SAMPLE_TYPE_H264:
     //case QBOX_SAMPLE_TYPE_H264_SLICE:
     //  QMed.QMedH264 qmedh264 = new QMed.QMedH264();
     //  qmed = qmedh264;
     //  break;
     case QBOX_SAMPLE_TYPE_QPCM:
       QMed.QMedPCM qmedpcm = new QMed.QMedPCM();
       qmed = qmedpcm;
       break;
     case QBOX_SAMPLE_TYPE_Q711:
       QMed.QMed711 qmed711 = new QMed.QMed711();
       qmed = qmed711;
       break;
     case QBOX_SAMPLE_TYPE_Q722:
       QMed.QMed722 qmed722 = new QMed.QMed722();
       qmed = qmed722;
       break;
     case QBOX_SAMPLE_TYPE_Q726:
       QMed.QMed726 qmed726 = new QMed.QMed726();
       qmed = qmed726;
       break;
     case QBOX_SAMPLE_TYPE_Q728:
       QMed.QMed728 qmed728 = new QMed.QMed728();
       qmed = qmed728;
       break;
     case QBOX_SAMPLE_TYPE_JPEG:
     case QBOX_SAMPLE_TYPE_MPEG2_ELEMENTARY:
     case QBOX_SAMPLE_TYPE_USER_METADATA:
     case QBOX_SAMPLE_TYPE_QMA:
     case QBOX_SAMPLE_TYPE_DEBUG:
     case QBOX_SAMPLE_TYPE_VIN_STATS_GLOBAL:
     case QBOX_SAMPLE_TYPE_VIN_STATS_MB:
       break;
     default:
       throw new Exception(string.Format("Unknown QMed type: {0}", sampleStreamType));
       }
       mSampleHeaderSize = (int)qmed.boxSize;
     }
     else
     {
       mSampleHeaderSize = 0;
     }
 }