OSDN Git Service

SoftFFmpegVideo: fix adpative video scaling problem
authorMichael Goffioul <michael.goffioul@gmail.com>
Sun, 3 Sep 2017 00:24:00 +0000 (08:24 +0800)
committerChih-Wei Huang <cwhuang@linux.org.tw>
Mon, 9 Oct 2017 17:48:13 +0000 (01:48 +0800)
The way I understand it is that the codec is not supposed to scale the
video frames to the buffer size. In case of adpative playback, the frames
may be smaller than the buffer, which corresponds to the max possible
frame size in the adaptive stream.

The patch also drops fiddling with the cropping attributes. I'm not sure
what was the purpose, but I couldn't find equivalent in other sw codecs
like avcdec or mpeg2dec, so I just dropped that and mimiced what the
other sw codecs are doing.

omx/SoftFFmpegVideo.cpp

index 4fdf5ae..48afb49 100644 (file)
@@ -589,21 +589,24 @@ int32_t SoftFFmpegVideo::drainOneOutputBuffer() {
     int64_t pts = AV_NOPTS_VALUE;
     uint8_t *dst = outHeader->pBuffer;
 
-    uint32_t width = outputBufferWidth();
-    uint32_t height = outputBufferHeight();
+    uint32_t bufferWidth = outputBufferWidth();
+    uint32_t bufferHeight = outputBufferHeight();
+    uint32_t frameWidth = mFrame->width;
+    uint32_t frameHeight = mFrame->height;
 
     data[0] = dst;
-    data[1] = dst + width * height;
-    data[2] = data[1] + (width / 2  * height / 2);
-    linesize[0] = width;
-    linesize[1] = width / 2;
-    linesize[2] = width / 2;
+    data[1] = dst + bufferWidth * bufferHeight;
+    data[2] = data[1] + (bufferWidth / 2  * bufferHeight / 2);
+    linesize[0] = bufferWidth;
+    linesize[1] = bufferWidth / 2;
+    linesize[2] = bufferWidth / 2;
 
-    ALOGV("drainOneOutputBuffer: frame_width=%d frame_height=%d width=%d height=%d ctx_width=%d ctx_height=%d", mFrame->width, mFrame->height, width, height, mCtx->width, mCtx->height);
+    ALOGD("drainOneOutputBuffer: frame_width=%d frame_height=%d buffer_width=%d buffer_height=%d ctx_width=%d ctx_height=%d mIsAdaptive=%d",
+          frameWidth, frameHeight, bufferWidth, bufferHeight, mCtx->width, mCtx->height, mIsAdaptive);
 
     int sws_flags = SWS_BICUBIC;
     mImgConvertCtx = sws_getCachedContext(mImgConvertCtx,
-           mFrame->width, mFrame->height, (AVPixelFormat)mFrame->format, width, height,
+           mFrame->width, mFrame->height, (AVPixelFormat)mFrame->format, mFrame->width, mFrame->height,
            AV_PIX_FMT_YUV420P, sws_flags, NULL, NULL, NULL);
     if (mImgConvertCtx == NULL) {
         ALOGE("Cannot initialize the conversion context");
@@ -613,7 +616,7 @@ int32_t SoftFFmpegVideo::drainOneOutputBuffer() {
             0, mFrame->height, data, linesize);
 
     outHeader->nOffset = 0;
-    outHeader->nFilledLen = (outputBufferWidth() * outputBufferHeight() * 3) / 2;
+    outHeader->nFilledLen = (bufferWidth * bufferHeight * 3) / 2;
     outHeader->nFlags = 0;
     if (mFrame->key_frame) {
         outHeader->nFlags |= OMX_BUFFERFLAG_SYNCFRAME;
@@ -697,6 +700,7 @@ void SoftFFmpegVideo::drainAllOutputBuffers() {
 }
 
 bool SoftFFmpegVideo::handlePortSettingsChange() {
+#if 0
     CropSettingsMode crop = kCropUnSet;
     uint32_t width  = outputBufferWidth();
     uint32_t height = outputBufferHeight();
@@ -715,6 +719,12 @@ bool SoftFFmpegVideo::handlePortSettingsChange() {
     SoftVideoDecoderOMXComponent::handlePortSettingsChange(
             &portWillReset, mCtx->width, mCtx->height, crop);
     return portWillReset;
+#else
+    bool portWillReset = false;
+    SoftVideoDecoderOMXComponent::handlePortSettingsChange(
+            &portWillReset, mCtx->width, mCtx->height);
+    return portWillReset;
+#endif
 }
 
 void SoftFFmpegVideo::onQueueFilled(OMX_U32 portIndex __unused) {