Bug 1010841 - Handle on-demand key frame request in OMX H.264 encoder. r=jesup
authorJohn Lin <jolin@mozilla.com>
Fri, 16 May 2014 01:56:00 -0400
changeset 202734 5b936e5fcacf18a141cc49531b86c66c51f069cd
parent 202733 dc9bcd6653f01738cd5421195aeb2b5766a9674b
child 202735 19eafdcdefe3c2571e7233b120e95e54d3a7b0e9
push id3741
push userasasaki@mozilla.com
push dateMon, 21 Jul 2014 20:25:18 +0000
treeherdermozilla-beta@4d6f46f5af68 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjesup
bugs1010841
milestone32.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 1010841 - Handle on-demand key frame request in OMX H.264 encoder. r=jesup
content/media/omx/OMXCodecWrapper.cpp
content/media/omx/OMXCodecWrapper.h
media/webrtc/signaling/src/media-conduit/WebrtcOMXH264VideoCodec.cpp
--- a/content/media/omx/OMXCodecWrapper.cpp
+++ b/content/media/omx/OMXCodecWrapper.cpp
@@ -446,16 +446,23 @@ OMXVideoEncoder::SetBitrate(int32_t aKbp
   msg->setInt32("videoBitrate", aKbps * 1000 /* kbps -> bps */);
   status_t result = mCodec->setParameters(msg);
   MOZ_ASSERT(result == OK);
   return result == OK ? NS_OK : NS_ERROR_FAILURE;
 }
 #endif
 
 nsresult
+OMXVideoEncoder::RequestIDRFrame()
+{
+  MOZ_ASSERT(mStarted, "Configure() should be called before RequestIDRFrame().");
+  return mCodec->requestIDRFrame() == OK ? NS_OK : NS_ERROR_FAILURE;
+}
+
+nsresult
 OMXAudioEncoder::Configure(int aChannels, int aInputSampleRate,
                            int aEncodedSampleRate)
 {
   MOZ_ASSERT(!mStarted);
 
   NS_ENSURE_TRUE(aChannels > 0 && aInputSampleRate > 0 && aEncodedSampleRate >= 0,
                  NS_ERROR_INVALID_ARG);
 
--- a/content/media/omx/OMXCodecWrapper.h
+++ b/content/media/omx/OMXCodecWrapper.h
@@ -277,16 +277,22 @@ public:
 #endif
 
   /**
    * Get current AVC codec config blob. The output format depends on the
    * aBlobFormat argument given when Configure() was called.
    */
   nsresult GetCodecConfig(nsTArray<uint8_t>* aOutputBuf);
 
+  /**
+   * Ask codec to generate an instantaneous decoding refresh (IDR) frame
+   * (defined in ISO/IEC 14496-10).
+   */
+  nsresult RequestIDRFrame();
+
 protected:
   virtual status_t AppendDecoderConfig(nsTArray<uint8_t>* aOutputBuf,
                                        ABuffer* aData) MOZ_OVERRIDE;
 
   // If configured to output MP4 format blob, AVC/H.264 encoder has to replace
   // NAL unit start code with the unit length as specified in
   // ISO/IEC 14496-15 5.2.3.
   virtual void AppendFrame(nsTArray<uint8_t>* aOutputBuf,
--- a/media/webrtc/signaling/src/media-conduit/WebrtcOMXH264VideoCodec.cpp
+++ b/media/webrtc/signaling/src/media-conduit/WebrtcOMXH264VideoCodec.cpp
@@ -688,16 +688,21 @@ WebrtcOMXH264VideoEncoder::Encode(const 
   if (!mOMXConfigured) {
     mOMX->Configure(mWidth, mHeight, mFrameRate,
                     OMXVideoEncoder::BlobFormat::AVC_NAL);
     mOMXConfigured = true;
     CODEC_LOGD("WebrtcOMXH264VideoEncoder:%p start OMX with image size:%ux%u",
                this, mWidth, mHeight);
   }
 
+  if (aFrameTypes && aFrameTypes->size() &&
+      ((*aFrameTypes)[0] == webrtc::kKeyFrame)) {
+    mOMX->RequestIDRFrame();
+  }
+
   // Wrap I420VideoFrame input with PlanarYCbCrImage for OMXVideoEncoder.
   layers::PlanarYCbCrData yuvData;
   yuvData.mYChannel = const_cast<uint8_t*>(aInputImage.buffer(webrtc::kYPlane));
   yuvData.mYSize = gfx::IntSize(aInputImage.width(), aInputImage.height());
   yuvData.mYStride = aInputImage.stride(webrtc::kYPlane);
   MOZ_ASSERT(aInputImage.stride(webrtc::kUPlane) == aInputImage.stride(webrtc::kVPlane));
   yuvData.mCbCrStride = aInputImage.stride(webrtc::kUPlane);
   yuvData.mCbChannel = const_cast<uint8_t*>(aInputImage.buffer(webrtc::kUPlane));