Upstream version 10.39.225.0
[platform/framework/web/crosswalk.git] / src / media / filters / ffmpeg_video_decoder.h
index 07cf2be..909a578 100644 (file)
@@ -9,10 +9,10 @@
 
 #include "base/callback.h"
 #include "base/memory/scoped_ptr.h"
-#include "base/memory/weak_ptr.h"
 #include "media/base/video_decoder.h"
 #include "media/base/video_decoder_config.h"
 #include "media/base/video_frame_pool.h"
+#include "media/ffmpeg/ffmpeg_deleters.h"
 
 struct AVCodecContext;
 struct AVFrame;
@@ -24,8 +24,6 @@ class SingleThreadTaskRunner;
 namespace media {
 
 class DecoderBuffer;
-class ScopedPtrAVFreeContext;
-class ScopedPtrAVFreeFrame;
 
 class MEDIA_EXPORT FFmpegVideoDecoder : public VideoDecoder {
  public:
@@ -33,61 +31,63 @@ class MEDIA_EXPORT FFmpegVideoDecoder : public VideoDecoder {
       const scoped_refptr<base::SingleThreadTaskRunner>& task_runner);
   virtual ~FFmpegVideoDecoder();
 
+  // Allow decoding of individual NALU. Entire frames are required by default.
+  // Disables low-latency mode. Must be called before Initialize().
+  void set_decode_nalus(bool decode_nalus) { decode_nalus_ = decode_nalus; }
+
   // VideoDecoder implementation.
+  virtual std::string GetDisplayName() const OVERRIDE;
   virtual void Initialize(const VideoDecoderConfig& config,
-                          const PipelineStatusCB& status_cb) OVERRIDE;
+                          bool low_delay,
+                          const PipelineStatusCB& status_cb,
+                          const OutputCB& output_cb) OVERRIDE;
   virtual void Decode(const scoped_refptr<DecoderBuffer>& buffer,
                       const DecodeCB& decode_cb) OVERRIDE;
   virtual void Reset(const base::Closure& closure) OVERRIDE;
-  virtual void Stop(const base::Closure& closure) OVERRIDE;
 
   // Callback called from within FFmpeg to allocate a buffer based on
-  // the dimensions of |codec_context|. See AVCodecContext.get_buffer
+  // the dimensions of |codec_context|. See AVCodecContext.get_buffer2
   // documentation inside FFmpeg.
-  int GetVideoBuffer(AVCodecContext *codec_context, AVFrame* frame);
+  int GetVideoBuffer(struct AVCodecContext* codec_context,
+                     AVFrame* frame,
+                     int flags);
 
  private:
   enum DecoderState {
     kUninitialized,
     kNormal,
-    kFlushCodec,
     kDecodeFinished,
     kError
   };
 
   // Handles decoding an unencrypted encoded buffer.
-  void DecodeBuffer(const scoped_refptr<DecoderBuffer>& buffer);
   bool FFmpegDecode(const scoped_refptr<DecoderBuffer>& buffer,
-                    scoped_refptr<VideoFrame>* video_frame);
+                    bool* has_produced_frame);
 
   // Handles (re-)initializing the decoder with a (new) config.
   // Returns true if initialization was successful.
-  bool ConfigureDecoder();
+  bool ConfigureDecoder(bool low_delay);
 
   // Releases resources associated with |codec_context_| and |av_frame_|
   // and resets them to NULL.
   void ReleaseFFmpegResources();
 
-  // Reset decoder and call |reset_cb_|.
-  void DoReset();
-
   scoped_refptr<base::SingleThreadTaskRunner> task_runner_;
-  base::WeakPtrFactory<FFmpegVideoDecoder> weak_factory_;
-  base::WeakPtr<FFmpegVideoDecoder> weak_this_;
 
   DecoderState state_;
 
-  DecodeCB decode_cb_;
-  base::Closure reset_cb_;
+  OutputCB output_cb_;
 
   // FFmpeg structures owned by this object.
-  scoped_ptr_malloc<AVCodecContext, ScopedPtrAVFreeContext> codec_context_;
-  scoped_ptr_malloc<AVFrame, ScopedPtrAVFreeFrame> av_frame_;
+  scoped_ptr<AVCodecContext, ScopedPtrAVFreeContext> codec_context_;
+  scoped_ptr<AVFrame, ScopedPtrAVFreeFrame> av_frame_;
 
   VideoDecoderConfig config_;
 
   VideoFramePool frame_pool_;
 
+  bool decode_nalus_;
+
   DISALLOW_COPY_AND_ASSIGN(FFmpegVideoDecoder);
 };