Bug 1240201: [opus] P2. Properly determine sample duration and time in webm demuxer. r=kinetik
authorJean-Yves Avenard <jyavenard@mozilla.com>
Fri, 22 Jan 2016 00:36:06 +1100
changeset 281237 d8eb98e2e4961b1ce5437e4b132bfba065c30239
parent 281236 c0a4a296569205598b370e34456fe23102d25e3d
child 281238 99f960e72e4d2def8762c40f00150e55b3db496c
push id70714
push userjyavenard@mozilla.com
push dateFri, 22 Jan 2016 15:51:07 +0000
treeherdermozilla-inbound@d8eb98e2e496 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerskinetik
bugs1240201
milestone46.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1240201: [opus] P2. Properly determine sample duration and time in webm demuxer. r=kinetik
dom/media/webm/WebMDemuxer.cpp
--- a/dom/media/webm/WebMDemuxer.cpp
+++ b/dom/media/webm/WebMDemuxer.cpp
@@ -24,16 +24,18 @@
 
 #include <algorithm>
 #include <stdint.h>
 
 #define VPX_DONT_DEFINE_STDINT_TYPES
 #include "vpx/vp8dx.h"
 #include "vpx/vpx_decoder.h"
 
+#include <opus/opus.h>
+
 #define WEBM_DEBUG(arg, ...) MOZ_LOG(gWebMDemuxerLog, mozilla::LogLevel::Debug, ("WebMDemuxer(%p)::%s: " arg, this, __func__, ##__VA_ARGS__))
 
 namespace mozilla {
 
 using namespace gfx;
 
 LazyLogModule gWebMDemuxerLog("WebMDemuxer");
 LazyLogModule gNesteggLog("Nestegg");
@@ -573,16 +575,27 @@ WebMDemuxer::GetNextPacket(TrackInfo::Tr
             int nsamples = mVorbisCounter.GetNumSamples(data, length);
             if (nsamples < 0) {
               return false;
             }
             duration =
               FramesToTimeUnit(nsamples, mInfo.mAudio.mRate).ToMicroseconds();
             break;
           }
+          case NESTEGG_CODEC_OPUS:
+          {
+            int nsamples =
+              opus_packet_get_nb_samples(data, length, mInfo.mAudio.mRate);
+            if (nsamples < 0) {
+              return false;
+            }
+            duration =
+              FramesToTimeUnit(nsamples, mInfo.mAudio.mRate).ToMicroseconds();
+            break;
+          }
           default:
             break;
         }
       }
     } else if (aType == TrackInfo::kVideoTrack) {
       vpx_codec_stream_info_t si;
       PodZero(&si);
       si.sz = sizeof(si);
@@ -607,17 +620,18 @@ WebMDemuxer::GetNextPacket(TrackInfo::Tr
     sample->mKeyframe = isKeyframe;
     if (discardPadding) {
       uint8_t c[8];
       BigEndian::writeInt64(&c[0], discardPadding);
       sample->mExtraData = new MediaByteBuffer;
       sample->mExtraData->AppendElements(&c[0], 8);
     }
     aSamples->Push(sample);
-    if (mAudioCodec == NESTEGG_CODEC_VORBIS) {
+    if (mAudioCodec == NESTEGG_CODEC_VORBIS ||
+        mAudioCodec == NESTEGG_CODEC_OPUS) {
       tstamp += duration;
     }
   }
   return true;
 }
 
 RefPtr<NesteggPacketHolder>
 WebMDemuxer::NextPacket(TrackInfo::TrackType aType)