Bug 1044742 - Fix multiple track support for EME - r=cpearce
authorEdwin Flores <eflores@mozilla.com>
Wed, 24 Sep 2014 10:04:49 +1200
changeset 222393 2abe5eac8b161013649d6a351ecd3f4e37825110
parent 222392 bd0198b0803d3489d7649dc94a7f26852a77dc34
child 222394 3855948c6f30f3bd8aa3e0be89cedd02349f5d8d
push id7107
push userraliiev@mozilla.com
push dateMon, 13 Oct 2014 17:43:31 +0000
treeherdermozilla-aurora@b4b34e0acc75 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerscpearce
bugs1044742
milestone35.0a1
Bug 1044742 - Fix multiple track support for EME - r=cpearce
content/media/fmp4/eme/EMEDecoderModule.cpp
media/libstagefright/binding/include/mp4_demuxer/DecoderData.h
media/libstagefright/frameworks/av/media/libstagefright/MPEG4Extractor.cpp
--- a/content/media/fmp4/eme/EMEDecoderModule.cpp
+++ b/content/media/fmp4/eme/EMEDecoderModule.cpp
@@ -195,17 +195,17 @@ EMEDecoderModule::Shutdown()
 
 already_AddRefed<MediaDataDecoder>
 EMEDecoderModule::CreateH264Decoder(const VideoDecoderConfig& aConfig,
                                     layers::LayersBackend aLayersBackend,
                                     layers::ImageContainer* aImageContainer,
                                     MediaTaskQueue* aVideoTaskQueue,
                                     MediaDataDecoderCallback* aCallback)
 {
-  if (mCDMDecodesVideo) {
+  if (mCDMDecodesVideo && aConfig.crypto.valid) {
     nsRefPtr<MediaDataDecoder> decoder(new EMEH264Decoder(mProxy,
                                                           aConfig,
                                                           aLayersBackend,
                                                           aImageContainer,
                                                           aVideoTaskQueue,
                                                           aCallback));
     return decoder.forget();
   }
@@ -214,43 +214,51 @@ EMEDecoderModule::CreateH264Decoder(cons
                                                              aLayersBackend,
                                                              aImageContainer,
                                                              aVideoTaskQueue,
                                                              aCallback));
   if (!decoder) {
     return nullptr;
   }
 
+  if (!aConfig.crypto.valid) {
+    return decoder.forget();
+  }
+
   nsRefPtr<MediaDataDecoder> emeDecoder(new EMEDecryptor(decoder,
                                                          aCallback,
                                                          mTaskQueue,
                                                          mProxy));
   return emeDecoder.forget();
 }
 
 already_AddRefed<MediaDataDecoder>
 EMEDecoderModule::CreateAudioDecoder(const AudioDecoderConfig& aConfig,
                                      MediaTaskQueue* aAudioTaskQueue,
                                      MediaDataDecoderCallback* aCallback)
 {
-  if (mCDMDecodesAudio) {
+  if (mCDMDecodesAudio && aConfig.crypto.valid) {
     nsRefPtr<MediaDataDecoder> decoder(new EMEAudioDecoder(mProxy,
                                                            aConfig,
                                                            aAudioTaskQueue,
                                                            aCallback));
     return decoder.forget();
   }
 
   nsRefPtr<MediaDataDecoder> decoder(mPDM->CreateAudioDecoder(aConfig,
                                                               aAudioTaskQueue,
                                                               aCallback));
   if (!decoder) {
     return nullptr;
   }
 
+  if (!aConfig.crypto.valid) {
+    return decoder.forget();
+  }
+
   nsRefPtr<MediaDataDecoder> emeDecoder(new EMEDecryptor(decoder,
                                                          aCallback,
                                                          mTaskQueue,
                                                          mProxy));
   return emeDecoder.forget();
 }
 
 } // namespace mozilla
--- a/media/libstagefright/binding/include/mp4_demuxer/DecoderData.h
+++ b/media/libstagefright/binding/include/mp4_demuxer/DecoderData.h
@@ -94,17 +94,16 @@ public:
 
   uint32_t channel_count;
   uint32_t bits_per_sample;
   uint32_t samples_per_second;
   int8_t frequency_index;
   int8_t aac_profile;
   mozilla::Vector<uint8_t> extra_data;
   mozilla::Vector<uint8_t> audio_specific_config;
-  CryptoTrack crypto;
 
   void Update(stagefright::sp<stagefright::MetaData>& aMetaData,
               const char* aMimeType);
   bool IsValid();
 
 private:
   friend class MP4Demuxer;
 };
--- a/media/libstagefright/frameworks/av/media/libstagefright/MPEG4Extractor.cpp
+++ b/media/libstagefright/frameworks/av/media/libstagefright/MPEG4Extractor.cpp
@@ -3313,16 +3313,38 @@ status_t MPEG4Source::read(
                 mBuffer->meta_data()->setInt64(
                         kKeyTargetTime, targetSampleTimeUs);
             }
 
             if (isSyncSample) {
                 mBuffer->meta_data()->setInt32(kKeyIsSyncFrame, 1);
             }
 
+            if (mSampleTable->hasCencInfo()) {
+                Vector<uint16_t> clearSizes;
+                Vector<uint32_t> cipherSizes;
+                uint8_t iv[16];
+                status_t err = mSampleTable->getSampleCencInfo(
+                        mCurrentSampleIndex, clearSizes, cipherSizes, iv);
+
+                if (err != OK) {
+                    return err;
+                }
+
+                const auto& meta = mBuffer->meta_data();
+                meta->setData(kKeyPlainSizes, 0, clearSizes.array(),
+                              clearSizes.size() * sizeof(uint16_t));
+                meta->setData(kKeyEncryptedSizes, 0, cipherSizes.array(),
+                              cipherSizes.size() * sizeof(uint32_t));
+                meta->setData(kKeyCryptoIV, 0, iv, sizeof(iv));
+                meta->setInt32(kKeyCryptoDefaultIVSize, mDefaultIVSize);
+                meta->setInt32(kKeyCryptoMode, mCryptoMode);
+                meta->setData(kKeyCryptoKey, 0, mCryptoKey, 16);
+            }
+
             ++mCurrentSampleIndex;
         }
 
         if (!mIsAVC) {
             *out = mBuffer;
             mBuffer = NULL;
 
             return OK;