Gnash  0.8.11dev
VideoDecoderFfmpeg.h
Go to the documentation of this file.
1 // VideoDecoderFfmpeg.h: Video decoding using the FFMPEG library.
2 //
3 // Copyright (C) 2007, 2008, 2009, 2010, 2011, 2012
4 // Free Software Foundation, Inc.
5 //
6 // This program is free software; you can redistribute it and/or modify
7 // it under the terms of the GNU General Public License as published by
8 // the Free Software Foundation; either version 3 of the License, or
9 // (at your option) any later version.
10 //
11 // This program is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
15 //
16 // You should have received a copy of the GNU General Public License
17 // along with this program; if not, write to the Free Software
18 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 
20 #ifndef GNASH_VIDEODECODERFFMPEG_H
21 #define GNASH_VIDEODECODERFFMPEG_H
22 
23 #ifdef HAVE_CONFIG_H
24 #include "gnashconfig.h"
25 #endif
26 
27 #include <vector>
28 #include <memory>
29 #include "dsodefs.h" //For DSOEXPORT
30 #include "VideoDecoder.h"
31 #include "MediaParser.h" // for videoCodecType enum
32 #include "ffmpegHeaders.h"
33 
34 namespace gnash {
35 namespace media {
36 namespace ffmpeg {
37 
38 // Forward declarations
39 class CodecContextWrapper;
40 #ifdef HAVE_SWSCALE_H
41 class SwsContextWrapper;
42 #endif
43 
44 
47 
48 public:
49 
51 
53 
55 
56  void push(const EncodedVideoFrame& buffer);
57 
58  std::unique_ptr<image::GnashImage> pop();
59 
60  bool peek();
61 
62  int width() const;
63 
64  int height() const;
65 
66 private:
67 
69  //
72  static CODECID flashToFfmpegCodec(videoCodecType format);
73 
83  std::unique_ptr<image::GnashImage> frameToImage(AVCodecContext* srcCtx,
84  const AVFrame& srcFrame);
85 
86  void init(enum CODECID format, int width, int height,
87  std::uint8_t* extradata=nullptr, int extradataSize=0);
88 
89  std::unique_ptr<image::GnashImage> decode(const std::uint8_t* input,
90  std::uint32_t input_size);
91 
92  std::unique_ptr<image::GnashImage> decode(const EncodedVideoFrame* vf)
93  {
94  return decode(vf->data(), vf->dataSize());
95  }
96 
97  AVCodec* _videoCodec;
98  std::unique_ptr<CodecContextWrapper> _videoCodecCtx;
99 
100 #if HAVE_SWSCALE_H
101  //
107  std::unique_ptr<SwsContextWrapper> _swsContext;
108 #endif
109 
110  std::vector<const EncodedVideoFrame*> _video_frames;
111 };
112 
113 } // gnash.media.ffmpeg namespace
114 } // gnash.media namespace
115 } // gnash namespace
116 
117 #endif // __VIDEODECODERFFMPEG_H__
DSOEXPORT ~VideoDecoderFfmpeg()
Definition: VideoDecoderFfmpeg.cpp:231
#define CODECID
Definition: ffmpegHeaders.h:137
bool peek()
Check whether a decoded frame is ready to be popped.
Definition: VideoDecoderFfmpeg.cpp:416
int width() const
Get the width in pixels of the Video.
Definition: VideoDecoderFfmpeg.cpp:236
Information about a video stream.
Definition: MediaParser.h:322
const std::uint8_t * data() const
Return pointer to actual data. Ownership retained by this class.
Definition: MediaParser.h:431
Abstract base class for embedded video decoders.
Definition: VideoDecoder.h:46
Anonymous namespace for callbacks, local functions, event handlers etc.
Definition: dbus_ext.cpp:40
An encoded video frame.
Definition: MediaParser.h:402
int height() const
Get the height in pixels of the Video.
Definition: VideoDecoderFfmpeg.cpp:243
std::unique_ptr< image::GnashImage > pop()
Pop a decoded frame from the decoder. THIS METHOD MAY BLOCK.
Definition: VideoDecoderFfmpeg.cpp:402
DSOEXPORT VideoDecoderFfmpeg(videoCodecType format, int width, int height)
Definition: VideoDecoderFfmpeg.cpp:118
std::uint32_t dataSize() const
Return size of data buffer.
Definition: MediaParser.h:434
videoCodecType
Video codec ids as defined in flash.
Definition: MediaParser.h:75
#define DSOEXPORT
Definition: dsodefs.h:55
FFMPEG based VideoDecoder.
Definition: VideoDecoderFfmpeg.h:46
void push(const EncodedVideoFrame &buffer)
Push an encoded video frame into the decoder.
Definition: VideoDecoderFfmpeg.cpp:396