[haiku-commits] haiku: hrev52239 - src/add-ons/media/plugins/ffmpeg

  • From: Stefano Ceccherini <stefano.ceccherini@xxxxxxxxx>
  • To: haiku-commits@xxxxxxxxxxxxx
  • Date: Thu, 16 Aug 2018 04:11:00 -0400 (EDT)

hrev52239 adds 1 changeset to branch 'master'
old head: 53086e436e0213b1f66e8081d2fd9b4bd3de4cc5
new head: 1da12a78de42382da35c1c20688679e6ebf84da5
overview: 
https://git.haiku-os.org/haiku/log/?qt=range&q=1da12a78de42+%5E53086e436e02

----------------------------------------------------------------------------

1da12a78de42: Reintroduced keeping the state of failed initialization.
  As Stephan said, some apps ignore the return value of Encode(),
  and since _OpenCodecIfNeeded() is called from there, this could
  cause wasting of cpu cycles.
  
  Change-Id: I80e1464d8532ebf80c514685ef3a25d98d8142fb

                             [ JackBurton79 <stefano.ceccherini@xxxxxxxxx> ]

----------------------------------------------------------------------------

Revision:    hrev52239
Commit:      1da12a78de42382da35c1c20688679e6ebf84da5
URL:         https://git.haiku-os.org/haiku/commit/?id=1da12a78de42
Author:      JackBurton79 <stefano.ceccherini@xxxxxxxxx>
Date:        Thu Aug 16 08:07:41 2018 UTC

----------------------------------------------------------------------------

2 files changed, 15 insertions(+), 7 deletions(-)
src/add-ons/media/plugins/ffmpeg/AVCodecEncoder.cpp | 13 ++++++++-----
src/add-ons/media/plugins/ffmpeg/AVCodecEncoder.h   |  9 +++++++--

----------------------------------------------------------------------------

diff --git a/src/add-ons/media/plugins/ffmpeg/AVCodecEncoder.cpp 
b/src/add-ons/media/plugins/ffmpeg/AVCodecEncoder.cpp
index ae533041dd..1a5498f3cc 100644
--- a/src/add-ons/media/plugins/ffmpeg/AVCodecEncoder.cpp
+++ b/src/add-ons/media/plugins/ffmpeg/AVCodecEncoder.cpp
@@ -44,7 +44,7 @@ AVCodecEncoder::AVCodecEncoder(uint32 codecID, int 
bitRateScale)
        fCodecID((CodecID)codecID),
        fCodec(NULL),
        fCodecContext(avcodec_alloc_context3(NULL)),
-       fCodecInitialized(false),
+       fCodecInitStatus(CODEC_INIT_NEEDED),
        fFrame(av_frame_alloc()),
        fSwsContext(NULL),
        fFramesWritten(0)
@@ -465,9 +465,12 @@ AVCodecEncoder::_Setup()
 bool
 AVCodecEncoder::_OpenCodecIfNeeded()
 {
-       if (fCodecInitialized)
+       if (fCodecInitStatus == CODEC_INIT_DONE)
                return true;
 
+       if (fCodecInitStatus == CODEC_INIT_FAILED)
+               return false;
+
        fCodecContext->strict_std_compliance = FF_COMPLIANCE_EXPERIMENTAL;
 
        // Some codecs need this to be set before open
@@ -478,13 +481,13 @@ AVCodecEncoder::_OpenCodecIfNeeded()
        // Open the codec
        int result = avcodec_open2(fCodecContext, fCodec, NULL);
        if (result >= 0)
-               fCodecInitialized = true;
+               fCodecInitStatus = CODEC_INIT_DONE;
        else
-               fCodecInitialized = false;
+               fCodecInitStatus = CODEC_INIT_FAILED;
 
        TRACE("  avcodec_open(%p, %p): %d\n", fCodecContext, fCodec, result);
 
-       return fCodecInitialized;
+       return fCodecInitStatus == CODEC_INIT_DONE;
 
 }
 
diff --git a/src/add-ons/media/plugins/ffmpeg/AVCodecEncoder.h 
b/src/add-ons/media/plugins/ffmpeg/AVCodecEncoder.h
index 9e5e8cfdb9..f120c7c88e 100644
--- a/src/add-ons/media/plugins/ffmpeg/AVCodecEncoder.h
+++ b/src/add-ons/media/plugins/ffmpeg/AVCodecEncoder.h
@@ -75,8 +75,13 @@ private:
                        CodecID                         fCodecID;
                        AVCodec*                        fCodec;
                        AVCodecContext*         fCodecContext;
-
-                       bool                            fCodecInitialized;
+                       
+                       enum {
+                               CODEC_INIT_NEEDED = 0,
+                               CODEC_INIT_DONE,
+                               CODEC_INIT_FAILED
+                       };
+                       uint32                          fCodecInitStatus;
 
                        // For video (color space conversion):
                        AVPicture                       fSrcFrame;


Other related posts:

  • » [haiku-commits] haiku: hrev52239 - src/add-ons/media/plugins/ffmpeg - Stefano Ceccherini