1 /******************************************************************************
2 * FOBS C++ wrapper Header
3 * Copyright (c) 2004 Omnividea Multimedia S.L
4 * Coded by JosŽ San Pedro Wandelmer
6 * This file is part of FOBS.
8 * FOBS is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU Lesser General Public License as
10 * published by the Free Software Foundation; either version 2.1
11 * of the License, or (at your option) any later version.
13 * FOBS 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 Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with FOBS; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 ******************************************************************************/
23 #ifndef __OMNIVIDEA_FOBS_DECODER_H
24 #define __OMNIVIDEA_FOBS_DECODER_H
32 //Forward declaration of ffmpeg structs
34 struct ReSampleContext
;
36 struct AVCodecContext
;
37 struct AVFormatContext
;
44 #ifndef AVCODEC_MAX_AUDIO_FRAME_SIZE
45 #define AVCODEC_MAX_AUDIO_FRAME_SIZE 192000
57 friend class Transcoder
;
64 bool audioEnabledFlag
;
66 bool eofReachedFlag
; /* true if eof reached */
68 AVFormatContext
*inputFile
;
69 AVInputFormat
*inputFileFormat
;
76 /*Decoded frame in different formats*/
80 AVPicture
*yuvPicture
;
85 AVPicture
*rgbPicture
;
88 TimeStamp currentRgba
;
90 AVPicture
*rgbaPicture
;
93 AVPicture
*decodedPicture
; //Format from the video
102 TimeStamp firstVideoPosition
;
103 bool firstVideoPositionFlag
;
104 TimeStamp firstVideoFramePosition
;
107 uint8_t decodedAudioFrame
[AVCODEC_MAX_AUDIO_FRAME_SIZE
];
108 int decodedAudioFrameSize
;
109 double audioTime
; //in Seconds
110 TimeStamp firstAudioFramePosition
;
111 TimeStamp positionAudio
;
112 TimeStamp firstAudioPosition
;
113 bool firstAudioPositionFlag
;
114 ReSampleContext
*audioResampler
;
116 //Temporals to change size
117 AVPicture
*transitionPicture
;
118 uint8_t *transitionPictureBuf
;
119 AVPicture
*transitionPictureRgb
;
120 uint8_t *transitionPictureBufRgb
;
122 int transitionPictureWidth
;
123 int transitionPictureHeight
;
124 //ImgReSampleContext *img_resample_ctx;
125 struct SwsContext
*img_resample_ctx
; /* for image resampling */
129 PacketBuffer
*videoBuffer
;
130 PacketBuffer
*audioBuffer
;
135 inline uint
_getWidth();
136 inline uint
_getHeight();
137 ReturnCode
reallocTransitionPicture(int newWidth
, int newHeight
);
138 bool compareTimeStamps(TimeStamp t1
, TimeStamp t2
);
140 bool audioResampleFlag
;
141 //uint8_t resampledAudioBuffer[AVCODEC_MAX_AUDIO_FRAME_SIZE];
144 TimeStamp
pts2TimeStamp(int64_t pts
, AVRational
*pts_timebase
);
145 int64_t timeStamp2pts(TimeStamp ts
, AVRational
*pts_timebase
);
148 virtual ReturnCode
readNextFrame();
149 virtual ReturnCode
placeAtNextFrame(bool videoFrame
);
150 virtual ReturnCode
decodeFrame();
151 virtual ReturnCode
decodeAudioFrame();
153 ReturnCode
setFrameFast(TimeStamp newPosition
);
154 ReturnCode
setFrameClassic(TimeStamp newPosition
);
155 ReturnCode
setAudioFast(TimeStamp newPosition
);
156 ReturnCode
setAudioClassic(TimeStamp newPosition
);
157 FrameIndex
frameIndexFromTimeStamp(TimeStamp t
);
158 TimeStamp
timeStampFromFrameIndex(FrameIndex f
);
161 ReturnCode
_setFrame(TimeStamp newPosition
);
165 Decoder(const char *filename
);
168 ReturnCode
testOpen();
169 ReturnCode
testClose();
170 void setAudioResampleFlag(bool flag
); //cap number of channels to two - Compatibility with JMF
174 //Video stream management
175 bool isVideoPresent();
176 virtual uint
getWidth();
177 virtual uint
getHeight();
178 virtual int getBitRate();
179 virtual double getFrameRate();
180 virtual TimeStamp
getDurationMilliseconds();
181 virtual double getDurationSeconds();
183 //Audio stream management
184 bool isAudioPresent();
185 void enableAudio(bool flag
);
186 uint
getAudioSampleRate(); //Samples per second
187 uint
getAudioBitRate(); //Kbits per second
188 uint
getAudioChannelNumber();
190 TimeStamp
getAVPosition();
192 inline virtual char* getFileName();
196 //End of stream query
197 //inline virtual bool moreFrames();
200 virtual FrameIndex
getFrameIndex();
201 inline virtual double getFrameTime();
202 virtual double getNextFrameTime();
203 double getAudioTime();
206 //Next&Prev video frame decoding
207 virtual ReturnCode
nextFrame();
208 virtual ReturnCode
nextAudioFrame();
209 virtual ReturnCode
prevFrame();
210 //Decoded video frame access
211 virtual byte
getCrFactor();
212 virtual byte
getCbFactor();
213 virtual byte
*getLuminance();
214 virtual byte
*getCr();
215 virtual byte
*getCb();
216 virtual byte
*getRGB();
217 virtual byte
*getRGBA();
218 virtual byte
*getRGBA(char *buf
);
219 byte
*getRGB(int width
, int height
);
220 ReturnCode
getRawFrame(AVPicture
** pict
, int* pix_fmt
);
225 uint8_t* getAudioSamples();
226 int getAudioSamplesSize();
229 //seeking functionality (video based)
230 virtual ReturnCode
setFrame(FrameIndex frameIndex
);
231 virtual ReturnCode
setFrameByTime(double seconds
);
232 virtual ReturnCode
setFrameByTime(TimeStamp milliseconds
);
233 virtual ReturnCode
setPosition(TimeStamp milliseconds
);
236 double getFirstFrameTime();
237 double getFirstAudioSampleTime();
239 AVCodecContext
*getAudioCodec();
240 AVCodecContext
*getVideoCodec();
247 } //namespace omnividea