Lines 50-63
FFReadStream::FFReadStream(FFReadHandler
Link Here
|
50 |
// m_pAvStream->r_frame_rate / (float) m_pAvStream->r_frame_rate_base); |
50 |
// m_pAvStream->r_frame_rate / (float) m_pAvStream->r_frame_rate_base); |
51 |
//m_pAvStream->time_length); |
51 |
//m_pAvStream->time_length); |
52 |
//m_dLength = avs->time_length; |
52 |
//m_dLength = avs->time_length; |
53 |
//printf("CODECRA %d %d %d\n", avs->codec.frame_rate, avs->codec.frame_rate_base, m_pAvStream->r_frame_rate_base); |
53 |
//printf("CODECRA %d %d %d\n", avs->codec->frame_rate, avs->codec->frame_rate_base, m_pAvStream->r_frame_rate_base); |
54 |
if (0 && avs->codec.codec_id == CODEC_ID_MPEG1VIDEO) |
54 |
if (0 && avs->codec->codec_id == CODEC_ID_MPEG1VIDEO) |
55 |
{ |
55 |
{ |
56 |
m_pAvContext = avcodec_alloc_context(); |
56 |
m_pAvContext = avcodec_alloc_context(); |
57 |
//AVCodec* codec = avcodec_find_encoder(avs->codec.codec_id); |
57 |
//AVCodec* codec = avcodec_find_encoder(avs->codec->codec_id); |
58 |
if (m_pAvContext) |
58 |
if (m_pAvContext) |
59 |
{ |
59 |
{ |
60 |
AVCodec* codec = avcodec_find_decoder(avs->codec.codec_id); |
60 |
AVCodec* codec = avcodec_find_decoder(avs->codec->codec_id); |
61 |
if (codec && avcodec_open(m_pAvContext, codec) == 0) |
61 |
if (codec && avcodec_open(m_pAvContext, codec) == 0) |
62 |
{ |
62 |
{ |
63 |
m_pAvContext->flags |= CODEC_FLAG_TRUNCATED; |
63 |
m_pAvContext->flags |= CODEC_FLAG_TRUNCATED; |
Lines 146-174
StreamInfo* FFReadStream::GetStreamInfo(
Link Here
|
146 |
m_StreamInfo.m_p->m_iQuality = 0; |
146 |
m_StreamInfo.m_p->m_iQuality = 0; |
147 |
m_StreamInfo.m_p->m_iSampleSize = 1;//m_Header.dwSampleSize; |
147 |
m_StreamInfo.m_p->m_iSampleSize = 1;//m_Header.dwSampleSize; |
148 |
|
148 |
|
149 |
switch (avs->codec.codec_type) |
149 |
switch (avs->codec->codec_type) |
150 |
{ |
150 |
{ |
151 |
case CODEC_TYPE_AUDIO: |
151 |
case CODEC_TYPE_AUDIO: |
152 |
m_StreamInfo.m_p->setAudio(avs->codec.channels, |
152 |
m_StreamInfo.m_p->setAudio(avs->codec->channels, |
153 |
avs->codec.sample_rate, |
153 |
avs->codec->sample_rate, |
154 |
avs->codec.frame_bits); |
154 |
avs->codec->frame_bits); |
155 |
m_StreamInfo.m_p->m_Type = StreamInfo::Audio; |
155 |
m_StreamInfo.m_p->m_Type = StreamInfo::Audio; |
156 |
m_StreamInfo.m_p->m_uiFormat = avs->codec.codec_tag; |
156 |
m_StreamInfo.m_p->m_uiFormat = avs->codec->codec_tag; |
157 |
AVM_WRITE("FF stream", "Audio Format: %.4s (0x%x)\n", |
157 |
AVM_WRITE("FF stream", "Audio Format: %.4s (0x%x)\n", |
158 |
(const char*)&avs->codec.codec_tag, avs->codec.codec_tag); |
158 |
(const char*)&avs->codec->codec_tag, avs->codec->codec_tag); |
159 |
break; |
159 |
break; |
160 |
case CODEC_TYPE_VIDEO: |
160 |
case CODEC_TYPE_VIDEO: |
161 |
m_StreamInfo.m_p->setVideo(avs->codec.width, avs->codec.height, |
161 |
m_StreamInfo.m_p->setVideo(avs->codec->width, avs->codec->height, |
162 |
0, avs->codec.sample_aspect_ratio.num / |
162 |
0, avs->codec->sample_aspect_ratio.num / |
163 |
(float) avs->codec.sample_aspect_ratio.den); |
163 |
(float) avs->codec->sample_aspect_ratio.den); |
164 |
m_StreamInfo.m_p->m_Type = StreamInfo::Video; |
164 |
m_StreamInfo.m_p->m_Type = StreamInfo::Video; |
165 |
m_StreamInfo.m_p->m_uiFormat = avs->codec.codec_tag; |
165 |
m_StreamInfo.m_p->m_uiFormat = avs->codec->codec_tag; |
166 |
break; |
166 |
break; |
167 |
default: |
167 |
default: |
168 |
return 0; |
168 |
return 0; |
169 |
} |
169 |
} |
170 |
if (m_StreamInfo.m_p->m_uiFormat == 0) |
170 |
if (m_StreamInfo.m_p->m_uiFormat == 0) |
171 |
m_StreamInfo.m_p->m_uiFormat = get_fcc(avs->codec.codec_id); |
171 |
m_StreamInfo.m_p->m_uiFormat = get_fcc(avs->codec->codec_id); |
172 |
} |
172 |
} |
173 |
|
173 |
|
174 |
return new StreamInfo(m_StreamInfo); |
174 |
return new StreamInfo(m_StreamInfo); |
Lines 189-195
uint_t FFReadStream::GetSampleSize() con
Link Here
|
189 |
|
189 |
|
190 |
IStream::StreamType FFReadStream::GetType() const |
190 |
IStream::StreamType FFReadStream::GetType() const |
191 |
{ |
191 |
{ |
192 |
switch (m_pHandler->m_pContext->streams[m_uiSId]->codec.codec_type) |
192 |
switch (m_pHandler->m_pContext->streams[m_uiSId]->codec->codec_type) |
193 |
{ |
193 |
{ |
194 |
case CODEC_TYPE_AUDIO: return IStream::Audio; |
194 |
case CODEC_TYPE_AUDIO: return IStream::Audio; |
195 |
case CODEC_TYPE_VIDEO: return IStream::Video; |
195 |
case CODEC_TYPE_VIDEO: return IStream::Video; |
Lines 200-233
IStream::StreamType FFReadStream::GetTyp
Link Here
|
200 |
uint_t FFReadStream::GetFormat(void *pFormat, uint_t lSize) const |
200 |
uint_t FFReadStream::GetFormat(void *pFormat, uint_t lSize) const |
201 |
{ |
201 |
{ |
202 |
AVStream* avs = m_pHandler->m_pContext->streams[m_uiSId]; |
202 |
AVStream* avs = m_pHandler->m_pContext->streams[m_uiSId]; |
203 |
switch (avs->codec.codec_type) |
203 |
switch (avs->codec->codec_type) |
204 |
{ |
204 |
{ |
205 |
case CODEC_TYPE_AUDIO: |
205 |
case CODEC_TYPE_AUDIO: |
206 |
if (pFormat && lSize >= sizeof(WAVEFORMATEX)) |
206 |
if (pFormat && lSize >= sizeof(WAVEFORMATEX)) |
207 |
{ |
207 |
{ |
208 |
WAVEFORMATEX* wf = (WAVEFORMATEX*) pFormat; |
208 |
WAVEFORMATEX* wf = (WAVEFORMATEX*) pFormat; |
209 |
wf->wFormatTag = avs->codec.codec_tag; |
209 |
wf->wFormatTag = avs->codec->codec_tag; |
210 |
if (wf->wFormatTag == 0) |
210 |
if (wf->wFormatTag == 0) |
211 |
wf->wFormatTag = get_fcc(avs->codec.codec_id); |
211 |
wf->wFormatTag = get_fcc(avs->codec->codec_id); |
212 |
//if (avs->codec.codec_tag == 0) wf->wFormatTag = av_codec_get_fourcc(avs->codec.codec_id); |
212 |
//if (avs->codec->codec_tag == 0) wf->wFormatTag = av_codec_get_fourcc(avs->codec->codec_id); |
213 |
//printf("CODEC %x %x %x\n", wf->wFormatTag, avs->codec.codec_id, avs->codec.codec_tag); |
213 |
//printf("CODEC %x %x %x\n", wf->wFormatTag, avs->codec->codec_id, avs->codec->codec_tag); |
214 |
wf->nChannels = avs->codec.channels; |
214 |
wf->nChannels = avs->codec->channels; |
215 |
wf->nSamplesPerSec = avs->codec.sample_rate; |
215 |
wf->nSamplesPerSec = avs->codec->sample_rate; |
216 |
wf->nAvgBytesPerSec = avs->codec.bit_rate / 8; |
216 |
wf->nAvgBytesPerSec = avs->codec->bit_rate / 8; |
217 |
wf->nBlockAlign = avs->codec.block_align; |
217 |
wf->nBlockAlign = avs->codec->block_align; |
218 |
wf->wBitsPerSample = avs->codec.bits_per_sample; |
218 |
wf->wBitsPerSample = avs->codec->bits_per_sample; |
219 |
if (lSize >= (sizeof(WAVEFORMATEX) + avs->codec.extradata_size) |
219 |
if (lSize >= (sizeof(WAVEFORMATEX) + avs->codec->extradata_size) |
220 |
&& avs->codec.extradata) |
220 |
&& avs->codec->extradata) |
221 |
{ |
221 |
{ |
222 |
wf->cbSize = avs->codec.extradata_size; |
222 |
wf->cbSize = avs->codec->extradata_size; |
223 |
memcpy(wf + 1, avs->codec.extradata, avs->codec.extradata_size); |
223 |
memcpy(wf + 1, avs->codec->extradata, avs->codec->extradata_size); |
224 |
} |
224 |
} |
225 |
else |
225 |
else |
226 |
wf->cbSize = 0; |
226 |
wf->cbSize = 0; |
227 |
} |
227 |
} |
228 |
//printf("EEEEEEEEEEE %d\n", avs->codec.extradata_size); |
228 |
//printf("EEEEEEEEEEE %d\n", avs->codec->extradata_size); |
229 |
return sizeof(WAVEFORMATEX) |
229 |
return sizeof(WAVEFORMATEX) |
230 |
+ ((avs->codec.extradata) ? avs->codec.extradata_size : 0); |
230 |
+ ((avs->codec->extradata) ? avs->codec->extradata_size : 0); |
231 |
case CODEC_TYPE_VIDEO: |
231 |
case CODEC_TYPE_VIDEO: |
232 |
if (pFormat && lSize >= sizeof(BITMAPINFOHEADER)) |
232 |
if (pFormat && lSize >= sizeof(BITMAPINFOHEADER)) |
233 |
{ |
233 |
{ |
Lines 235-261
uint_t FFReadStream::GetFormat(void *pFo
Link Here
|
235 |
//printf("FORMAT %p %d %d\n", pFormat, m_uiSId, avc->width); |
235 |
//printf("FORMAT %p %d %d\n", pFormat, m_uiSId, avc->width); |
236 |
memset(bh, 0, sizeof(BITMAPINFOHEADER)); |
236 |
memset(bh, 0, sizeof(BITMAPINFOHEADER)); |
237 |
bh->biSize = sizeof(BITMAPINFOHEADER); |
237 |
bh->biSize = sizeof(BITMAPINFOHEADER); |
238 |
bh->biWidth = avs->codec.width; |
238 |
bh->biWidth = avs->codec->width; |
239 |
bh->biHeight = avs->codec.height; |
239 |
bh->biHeight = avs->codec->height; |
240 |
bh->biPlanes = 1; |
240 |
bh->biPlanes = 1; |
241 |
bh->biCompression = avs->codec.codec_tag; |
241 |
bh->biCompression = avs->codec->codec_tag; |
242 |
bh->biBitCount = avs->codec.bits_per_sample; |
242 |
bh->biBitCount = avs->codec->bits_per_sample; |
243 |
// hack which might be eventually usefull |
243 |
// hack which might be eventually usefull |
244 |
memcpy(&bh->biXPelsPerMeter, &m_pHandler->m_pContext, sizeof(void*)); |
244 |
memcpy(&bh->biXPelsPerMeter, &m_pHandler->m_pContext, sizeof(void*)); |
245 |
if (bh->biCompression == 0) |
245 |
if (bh->biCompression == 0) |
246 |
bh->biCompression = get_fcc(avs->codec.codec_id); |
246 |
bh->biCompression = get_fcc(avs->codec->codec_id); |
247 |
if (lSize >= (sizeof(BITMAPINFOHEADER) + avs->codec.extradata_size) |
247 |
if (lSize >= (sizeof(BITMAPINFOHEADER) + avs->codec->extradata_size) |
248 |
&& avs->codec.extradata) |
248 |
&& avs->codec->extradata) |
249 |
{ |
249 |
{ |
250 |
bh->biSize += avs->codec.extradata_size; |
250 |
bh->biSize += avs->codec->extradata_size; |
251 |
memcpy(bh + 1, avs->codec.extradata, avs->codec.extradata_size); |
251 |
memcpy(bh + 1, avs->codec->extradata, avs->codec->extradata_size); |
252 |
//printf("COPY EXTRA %d\n", avs->extradata_size); |
252 |
//printf("COPY EXTRA %d\n", avs->extradata_size); |
253 |
//for (unsigned i = 0; i < lSize; i++) printf("%d 0x%x\n", i, ((uint8_t*)pFormat)[i]); |
253 |
//for (unsigned i = 0; i < lSize; i++) printf("%d 0x%x\n", i, ((uint8_t*)pFormat)[i]); |
254 |
} |
254 |
} |
255 |
//BitmapInfo(*bh).Print(); |
255 |
//BitmapInfo(*bh).Print(); |
256 |
} |
256 |
} |
257 |
return sizeof(BITMAPINFOHEADER) |
257 |
return sizeof(BITMAPINFOHEADER) |
258 |
+ ((avs->codec.extradata) ? avs->codec.extradata_size : 0); |
258 |
+ ((avs->codec->extradata) ? avs->codec->extradata_size : 0); |
259 |
default: |
259 |
default: |
260 |
return 0; |
260 |
return 0; |
261 |
} |
261 |
} |
Lines 291-297
StreamPacket* FFReadStream::ReadPacket()
Link Here
|
291 |
if (m_dLength < m_dTimestamp) |
291 |
if (m_dLength < m_dTimestamp) |
292 |
m_dLength = m_dTimestamp; |
292 |
m_dLength = m_dTimestamp; |
293 |
|
293 |
|
294 |
//printf("READSTREAM %f sid:%d qsz:%d s:%d frm: %d\n", m_dTimestamp, m_uiSId, m_Packets.size(), p->size, m_pAvStream->codec.frame_number); |
294 |
//printf("READSTREAM %f sid:%d qsz:%d s:%d frm: %d\n", m_dTimestamp, m_uiSId, m_Packets.size(), p->size, m_pAvStream->codec->frame_number); |
295 |
return p; |
295 |
return p; |
296 |
} |
296 |
} |
297 |
|
297 |
|
Lines 310-316
int FFReadStream::SeekTime(double time)
Link Here
|
310 |
{ |
310 |
{ |
311 |
if (time < 1.) |
311 |
if (time < 1.) |
312 |
{ |
312 |
{ |
313 |
if (m_pAvStream->codec.codec_type == CODEC_TYPE_AUDIO) |
313 |
if (m_pAvStream->codec->codec_type == CODEC_TYPE_AUDIO) |
314 |
// check if more streams are available |
314 |
// check if more streams are available |
315 |
// and seek only with the video |
315 |
// and seek only with the video |
316 |
return 0; |
316 |
return 0; |