Merge pull request #3112 from koying/fixcurlopenssl
[vuplus_xbmc] / xbmc / video / FFmpegVideoDecoder.h
1 #ifndef FFMPEGVIDEODECODER_H
2 #define FFMPEGVIDEODECODER_H
3
4 /*
5  *      Copyright (C) 2005-2013 Team XBMC
6  *      http://xbmc.org
7  *
8  *  This Program is free software; you can redistribute it and/or modify
9  *  it under the terms of the GNU General Public License as published by
10  *  the Free Software Foundation; either version 2, or (at your option)
11  *  any later version.
12  *
13  *  This Program is distributed in the hope that it will be useful,
14  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  *  GNU General Public License for more details.
17  *
18  *  You should have received a copy of the GNU General Public License
19  *  along with XBMC; see the file COPYING.  If not, see
20  *  <http://www.gnu.org/licenses/>.
21  *
22  */
23
24 #include "utils/StdString.h"
25
26 class CBaseTexture;
27 class m_dllAvFormat;
28 class m_dllAvCodec;
29 class m_dllAvUtil;
30 class m_dllSwScale;
31
32 struct AVFormatContext;
33 struct AVCodecContext;
34 struct AVCodec;
35 struct AVFrame;
36
37 /**
38  * A simple FFMpeg-based background video decoder.
39  * 
40  * This class only decodes the video using the standard FFmpeg calls, so likely no hardware acceleration.
41  * No audio decoding, and no rendering.
42  * 
43  */
44 class FFmpegVideoDecoder
45 {
46 public:
47   FFmpegVideoDecoder();
48   ~FFmpegVideoDecoder();
49
50   /**
51    * Opens the video file for decoding. Supports all the formats supported by the used FFmpeg.
52    * The file must have at least one video track. If it has more than one, the first video track
53    * would be decoded.
54    * 
55    * If an existing stream was opened, it is automatically closed and the new stream is opened.
56    * 
57    * Returns true if the file was opened successfully, and false otherwise, in which case
58    * the getErrorMsg() function could be used to retrieve the reason.
59    * 
60    * @param filename The video file name, which must be translated through CSpecialProtocol::TranslatePath()
61    */
62   bool open( const CStdString& filename );
63
64   /**
65    * Returns true if the decoder has the video file opened.
66    */
67   bool isOpened() const;
68
69   /**
70    * Returns the movie duration in seconds or 0.0 if the duration is not available. For some formats
71    * is calculated through the heuristics, and the video might not really be that long (for example if it is incomplete).
72    * The total number of frames is calculated by multiplying the duration by getFramesPerSecond()
73    */
74   double getDuration() const;
75   
76   /**
77    * Returns the frames per second for this video
78    */
79   double getFramesPerSecond() const;
80   
81   /**
82    * Returns the original video width or 0 if the video wasn't opened.
83    */  
84   unsigned int getWidth() const;
85
86   /**
87    * Returns the original video height or 0 if the video wasn't opened.
88    */  
89   unsigned int getHeight() const;
90
91   /**
92    * Returns the last rendered frame number.
93    */
94   double getLastFrameTime() const;
95
96   /**
97    * Returns the AVFormatContext structure associated with this video format
98    */  
99   const AVFormatContext * getAVFormatContext() const;
100
101   /**
102    * Returns the AVCodecContext structure associated with this video codec
103    */  
104   const AVCodecContext * getAVCodecContext() const;
105   
106   /**
107    * Returns the AVCodec structure associated with this video codec
108    */  
109   const AVCodec * getAVCodec() const;
110
111   /**
112    * Returns the error message text if opening the video failed
113    */  
114   CStdString getErrorMsg() const;
115
116   /**
117    * Decodes and renders the next video frame into the provided texture which
118    * must be in a XB_FMT_A8R8G8B8 format.
119    * The frame will be rescaled to fit the whole texture (i.e. texture width/height)
120    * so make sure the texture aspect ratio is the same as in the original movie.
121    * 
122    * @param texture The texture to render the frame into. Must be preallocated, 
123    * have the appropriate width/height and in XB_FMT_A8R8G8B8 format.
124    * 
125    * @return true if the frame rendered, false if there are no more frames
126    */  
127   bool nextFrame( CBaseTexture * texture );
128
129   /**
130         * Seeks to a specific time position in the video file. Note that the seek is limited to the keyframes only.
131         * @param time The time to seek to, in seconds
132         * @return true if the seek succeed, false if failed
133         */
134   bool seek( double time );
135
136   /**
137    * Closes the video stream.
138    */  
139   void close();
140
141 private:
142   bool readFrame( int frame );
143   
144   DllAvFormat     *m_dllAvFormat;
145   DllAvCodec      *m_dllAvCodec;
146   DllAvUtil       *m_dllAvUtil;
147   DllSwScale      *m_dllSwScale;
148   AVFormatContext *m_pFormatCtx;
149   AVCodecContext  *m_pCodecCtx;
150   AVCodec         *m_pCodec;
151   AVFrame         *m_pFrame;
152   AVPicture       *m_pFrameRGB;
153   int              m_videoStream;
154   double           m_lastFrameTime;
155   
156   // The dimensions of the allocated pFrameRGB
157   unsigned int     m_frameRGBwidth;
158   unsigned int     m_frameRGBheight;
159   
160   CStdString       m_errorMsg;
161 };
162
163 #endif