OSDN Git Service

Allow to build with libav and ffmpeg
[android-x86/external-stagefright-plugins.git] / omx / SoftFFmpegVideo.cpp
index 8dd29be..101d3ef 100644 (file)
@@ -86,12 +86,6 @@ void SoftFFmpegVideo::setDefaultCtx(AVCodecContext *avctx, const AVCodec *codec)
     int fast = 1;
 
     avctx->workaround_bugs   = 1;
-    avctx->lowres            = 0;
-    if(avctx->lowres > codec->max_lowres){
-        ALOGW("The maximum value for lowres supported by the decoder is %d",
-                codec->max_lowres);
-        avctx->lowres= codec->max_lowres;
-    }
     avctx->idct_algo         = 0;
     avctx->skip_frame        = AVDISCARD_DEFAULT;
     avctx->skip_idct         = AVDISCARD_DEFAULT;
@@ -99,10 +93,11 @@ void SoftFFmpegVideo::setDefaultCtx(AVCodecContext *avctx, const AVCodec *codec)
     avctx->error_concealment = 3;
     avctx->thread_count      = 0;
 
-    if(avctx->lowres) avctx->flags |= CODEC_FLAG_EMU_EDGE;
-    if (fast)   avctx->flags2 |= CODEC_FLAG2_FAST;
-    if(codec->capabilities & CODEC_CAP_DR1)
+    if (fast)   avctx->flags2 |= AV_CODEC_FLAG2_FAST;
+#ifdef CODEC_FLAG_EMU_EDGE
+    if (codec->capabilities & AV_CODEC_CAP_DR1)
         avctx->flags |= CODEC_FLAG_EMU_EDGE;
+#endif
 }
 
 status_t SoftFFmpegVideo::initDecoder(enum AVCodecID codecID) {
@@ -142,6 +137,7 @@ void SoftFFmpegVideo::deInitDecoder() {
         }
         if (mCodecAlreadyOpened) {
             avcodec_close(mCtx);
+            mCodecAlreadyOpened = false;
         }
         av_free(mCtx);
         mCtx = NULL;
@@ -365,7 +361,7 @@ int32_t SoftFFmpegVideo::handleExtradata() {
             int orig_extradata_size = mCtx->extradata_size;
             mCtx->extradata_size += inHeader->nFilledLen;
             mCtx->extradata = (uint8_t *)realloc(mCtx->extradata,
-                    mCtx->extradata_size + FF_INPUT_BUFFER_PADDING_SIZE);
+                    mCtx->extradata_size + AV_INPUT_BUFFER_PADDING_SIZE);
             if (!mCtx->extradata) {
                 ALOGE("ffmpeg video decoder failed to alloc extradata memory.");
                 return ERR_OOM;
@@ -375,7 +371,7 @@ int32_t SoftFFmpegVideo::handleExtradata() {
                     inHeader->pBuffer + inHeader->nOffset,
                     inHeader->nFilledLen);
             memset(mCtx->extradata + mCtx->extradata_size, 0,
-                    FF_INPUT_BUFFER_PADDING_SIZE);
+                    AV_INPUT_BUFFER_PADDING_SIZE);
         }
     }
 
@@ -470,7 +466,7 @@ int32_t SoftFFmpegVideo::decodeVideo() {
     }
 
     if (mEOSStatus == INPUT_EOS_SEEN && (!inHeader || inHeader->nFilledLen == 0)
-        && !(mCtx->codec->capabilities & CODEC_CAP_DELAY)) {
+        && !(mCtx->codec->capabilities & AV_CODEC_CAP_DELAY)) {
         return ERR_FLUSHED;
     }
 
@@ -490,8 +486,8 @@ int32_t SoftFFmpegVideo::decodeVideo() {
         if (!gotPic) {
             ALOGI("ffmpeg video decoder failed to get frame.");
             //stop sending empty packets if the decoder is finished
-            if (mEOSStatus != INPUT_DATA_AVAILABLE && mCtx->codec->capabilities & CODEC_CAP_DELAY &&
-                !inHeader || inHeader->nFilledLen == 0) {
+            if ((mEOSStatus != INPUT_DATA_AVAILABLE && (mCtx->codec->capabilities & AV_CODEC_CAP_DELAY) &&
+                !inHeader) || inHeader->nFilledLen == 0) {
                 ret = ERR_FLUSHED;
             } else {
                 ret = ERR_NO_FRM;
@@ -517,20 +513,21 @@ int32_t SoftFFmpegVideo::drainOneOutputBuffer() {
     BufferInfo *outInfo = *outQueue.begin();
     OMX_BUFFERHEADERTYPE *outHeader = outInfo->mHeader;
 
-    AVPicture pict;
+    uint8_t *data[4];
+    int linesize[4];
+
     int64_t pts = AV_NOPTS_VALUE;
     uint8_t *dst = outHeader->pBuffer;
 
     uint32_t width = outputBufferWidth();
     uint32_t height = outputBufferHeight();
 
-    memset(&pict, 0, sizeof(AVPicture));
-    pict.data[0] = dst;
-    pict.data[1] = dst + width * height;
-    pict.data[2] = pict.data[1] + (width / 2  * height / 2);
-    pict.linesize[0] = width;
-    pict.linesize[1] = width / 2;
-    pict.linesize[2] = width / 2;
+    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;
 
     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);
 
@@ -543,7 +540,7 @@ int32_t SoftFFmpegVideo::drainOneOutputBuffer() {
         return ERR_SWS_FAILED;
     }
     sws_scale(mImgConvertCtx, mFrame->data, mFrame->linesize,
-            0, height, pict.data, pict.linesize);
+            0, height, data, linesize);
 
     outHeader->nOffset = 0;
     outHeader->nFilledLen = (outputBufferWidth() * outputBufferHeight() * 3) / 2;
@@ -553,9 +550,12 @@ int32_t SoftFFmpegVideo::drainOneOutputBuffer() {
     }
 
     //process timestamps
+#ifndef LIBAV_CONFIG_H
     if (decoder_reorder_pts == -1) {
         pts = av_frame_get_best_effort_timestamp(mFrame);
-    } else if (decoder_reorder_pts) {
+    } else
+#endif
+    if (decoder_reorder_pts) {
         pts = mFrame->pkt_pts;
     } else {
         pts = mFrame->pkt_dts;
@@ -739,6 +739,9 @@ void SoftFFmpegVideo::onPortFlushCompleted(OMX_U32 portIndex) {
 
 void SoftFFmpegVideo::onReset() {
     ALOGV("onReset()");
+    enum AVCodecID codecID = mCtx->codec_id;
+    deInitDecoder();
+    initDecoder(codecID);
     SoftVideoDecoderOMXComponent::onReset();
     mSignalledError = false;
     mExtradataReady = false;