Bug 1320705: P4. Pass discard padding information from webm container. r=kinetik
authorJean-Yves Avenard <jyavenard@mozilla.com>
Wed, 30 Nov 2016 20:40:59 +1100
changeset 325258 d330cc7e9094d9e8d832280e3f0c125f876f8b68
parent 325257 18b5d19d0abc3fc05d38e85c69b02fada82fae2b
child 325259 7495e866529ebd20352e63eb2b25dfa688a7dfd2
push id24
push usermaklebus@msu.edu
push dateTue, 20 Dec 2016 03:11:33 +0000
reviewerskinetik
bugs1320705
milestone53.0a1
Bug 1320705: P4. Pass discard padding information from webm container. r=kinetik MozReview-Commit-ID: G2OnV1iZohn
dom/media/webm/WebMDemuxer.cpp
--- a/dom/media/webm/WebMDemuxer.cpp
+++ b/dom/media/webm/WebMDemuxer.cpp
@@ -610,17 +610,19 @@ WebMDemuxer::GetNextPacket(TrackInfo::Tr
     mLastVideoFrameTime = Some(tstamp);
   }
 
   if (mIsMediaSource && next_tstamp == INT64_MIN) {
     return false;
   }
 
   int64_t discardPadding = 0;
-  (void) nestegg_packet_discard_padding(holder->Packet(), &discardPadding);
+  if (aType == TrackInfo::kAudioTrack) {
+    (void) nestegg_packet_discard_padding(holder->Packet(), &discardPadding);
+  }
 
   int packetEncryption = nestegg_packet_encryption(holder->Packet());
 
   for (uint32_t i = 0; i < count; ++i) {
     unsigned char* data;
     size_t length;
     r = nestegg_packet_data(holder->Packet(), i, &data, &length);
     if (r == -1) {
@@ -686,20 +688,30 @@ WebMDemuxer::GetNextPacket(TrackInfo::Tr
       sample = new MediaRawData(data, length);
     }
     sample->mTimecode = tstamp;
     sample->mTime = tstamp;
     sample->mDuration = next_tstamp - tstamp;
     sample->mOffset = holder->Offset();
     sample->mKeyframe = isKeyframe;
     if (discardPadding && i == count - 1) {
-      uint8_t c[8];
-      BigEndian::writeInt64(&c[0], discardPadding);
-      sample->mExtraData = new MediaByteBuffer;
-      sample->mExtraData->AppendElements(&c[0], 8);
+      CheckedInt64 discardFrames;
+      if (discardPadding < 0) {
+        // This is an invalid value as discard padding should never be negative.
+        // Set to maximum value so that the decoder will reject it as it's
+        // greater than the number of frames available.
+        discardFrames = INT32_MAX;
+        WEBM_DEBUG("Invalid negative discard padding");
+      } else {
+        discardFrames = TimeUnitToFrames(
+          media::TimeUnit::FromNanoseconds(discardPadding), mInfo.mAudio.mRate);
+      }
+      if (discardFrames.isValid()) {
+        sample->mDiscardPadding = discardFrames.value();
+      }
     }
 
     if (packetEncryption == NESTEGG_PACKET_HAS_SIGNAL_BYTE_UNENCRYPTED ||
         packetEncryption == NESTEGG_PACKET_HAS_SIGNAL_BYTE_ENCRYPTED) {
       nsAutoPtr<MediaRawDataWriter> writer(sample->CreateWriter());
       unsigned char const* iv;
       size_t ivLength;
       nestegg_packet_iv(holder->Packet(), &iv, &ivLength);