204
static void init_video_codec (ff_video_decoder_t *this) {
214
static const ff_codec_t ff_video_lookup[] = {
215
{BUF_VIDEO_MSMPEG4_V1, CODEC_ID_MSMPEG4V1, "Microsoft MPEG-4 v1 (ffmpeg)"},
216
{BUF_VIDEO_MSMPEG4_V2, CODEC_ID_MSMPEG4V2, "Microsoft MPEG-4 v2 (ffmpeg)"},
217
{BUF_VIDEO_MSMPEG4_V3, CODEC_ID_MSMPEG4V3, "Microsoft MPEG-4 v3 (ffmpeg)"},
218
{BUF_VIDEO_WMV7, CODEC_ID_WMV1, "MS Windows Media Video 7 (ffmpeg)"},
219
{BUF_VIDEO_WMV8, CODEC_ID_WMV2, "MS Windows Media Video 8 (ffmpeg)"},
220
{BUF_VIDEO_MPEG4, CODEC_ID_MPEG4, "ISO MPEG-4 (ffmpeg)"},
221
{BUF_VIDEO_XVID, CODEC_ID_MPEG4, "ISO MPEG-4 (XviD, ffmpeg)"},
222
{BUF_VIDEO_DIVX5, CODEC_ID_MPEG4, "ISO MPEG-4 (DivX5, ffmpeg)"},
223
{BUF_VIDEO_3IVX, CODEC_ID_MPEG4, "ISO MPEG-4 (3ivx, ffmpeg)"},
224
{BUF_VIDEO_JPEG, CODEC_ID_MJPEG, "Motion JPEG (ffmpeg)"},
225
{BUF_VIDEO_MJPEG, CODEC_ID_MJPEG, "Motion JPEG (ffmpeg)"},
226
{BUF_VIDEO_MJPEG_B, CODEC_ID_MJPEGB, "Motion JPEG B (ffmpeg"},
227
{BUF_VIDEO_I263, CODEC_ID_H263I, "ITU H.263 (ffmpeg)"},
228
{BUF_VIDEO_H263, CODEC_ID_H263, "H.263 (ffmpeg)"},
229
{BUF_VIDEO_RV10, CODEC_ID_RV10, "Real Video 1.0 (ffmpeg)"},
230
{BUF_VIDEO_RV20, CODEC_ID_RV20, "Real Video 2.0 (ffmpeg)"},
231
{BUF_VIDEO_IV31, CODEC_ID_INDEO3, "Indeo Video 3.1 (ffmpeg)"},
232
{BUF_VIDEO_IV32, CODEC_ID_INDEO3, "Indeo Video 3.2 (ffmpeg)"},
233
{BUF_VIDEO_SORENSON_V1, CODEC_ID_SVQ1, "Sorenson Video 1 (ffmpeg)"},
234
{BUF_VIDEO_SORENSON_V3, CODEC_ID_SVQ3, "Sorenson Video 3 (ffmpeg)"},
235
{BUF_VIDEO_DV, CODEC_ID_DVVIDEO, "DV (ffmpeg)"},
236
{BUF_VIDEO_HUFFYUV, CODEC_ID_HUFFYUV, "HuffYUV (ffmpeg)"},
237
{BUF_VIDEO_VP31, CODEC_ID_VP3, "On2 VP3.1 (ffmpeg)"},
238
{BUF_VIDEO_4XM, CODEC_ID_4XM, "4X Video (ffmpeg)"},
239
{BUF_VIDEO_CINEPAK, CODEC_ID_CINEPAK, "Cinepak (ffmpeg)"},
240
{BUF_VIDEO_MSVC, CODEC_ID_MSVIDEO1, "Microsoft Video 1 (ffmpeg)"},
241
{BUF_VIDEO_MSRLE, CODEC_ID_MSRLE, "Microsoft RLE (ffmpeg)"},
242
{BUF_VIDEO_RPZA, CODEC_ID_RPZA, "Apple Quicktime Video/RPZA (ffmpeg)"},
243
{BUF_VIDEO_CYUV, CODEC_ID_CYUV, "Creative YUV (ffmpeg)"},
244
{BUF_VIDEO_ROQ, CODEC_ID_ROQ, "Id Software RoQ (ffmpeg)"},
245
{BUF_VIDEO_IDCIN, CODEC_ID_IDCIN, "Id Software CIN (ffmpeg)"},
246
{BUF_VIDEO_WC3, CODEC_ID_XAN_WC3, "Xan (ffmpeg)"},
247
{BUF_VIDEO_VQA, CODEC_ID_WS_VQA, "Westwood Studios VQA (ffmpeg)"},
248
{BUF_VIDEO_INTERPLAY, CODEC_ID_INTERPLAY_VIDEO, "Interplay MVE (ffmpeg)"},
249
{BUF_VIDEO_FLI, CODEC_ID_FLIC, "FLIC Video (ffmpeg)"},
250
{BUF_VIDEO_8BPS, CODEC_ID_8BPS, "Planar RGB (ffmpeg)"},
251
{BUF_VIDEO_SMC, CODEC_ID_SMC, "Apple Quicktime Graphics/SMC (ffmpeg)"},
252
{BUF_VIDEO_DUCKTM1, CODEC_ID_TRUEMOTION1,"Duck TrueMotion v1 (ffmpeg)"},
253
{BUF_VIDEO_DUCKTM2, CODEC_ID_TRUEMOTION2,"Duck TrueMotion v2 (ffmpeg)"},
254
{BUF_VIDEO_VMD, CODEC_ID_VMDVIDEO, "Sierra VMD Video (ffmpeg)"},
255
{BUF_VIDEO_ZLIB, CODEC_ID_ZLIB, "ZLIB Video (ffmpeg)"},
256
{BUF_VIDEO_MSZH, CODEC_ID_MSZH, "MSZH Video (ffmpeg)"},
257
{BUF_VIDEO_ASV1, CODEC_ID_ASV1, "ASV v1 Video (ffmpeg)"},
258
{BUF_VIDEO_ASV2, CODEC_ID_ASV2, "ASV v2 Video (ffmpeg)"},
259
{BUF_VIDEO_ATIVCR1, CODEC_ID_VCR1, "ATI VCR-1 (ffmpeg)"},
260
{BUF_VIDEO_FLV1, CODEC_ID_FLV1, "Flash Video (ffmpeg)"},
261
{BUF_VIDEO_QTRLE, CODEC_ID_QTRLE, "Apple Quicktime Animation/RLE (ffmpeg)"},
262
{BUF_VIDEO_H264, CODEC_ID_H264, "H.264/AVC (ffmpeg)"},
263
{BUF_VIDEO_H261, CODEC_ID_H261, "H.261 (ffmpeg)"},
264
{BUF_VIDEO_AASC, CODEC_ID_AASC, "Autodesk Video (ffmpeg)"},
265
{BUF_VIDEO_LOCO, CODEC_ID_LOCO, "LOCO (ffmpeg)"},
266
{BUF_VIDEO_QDRW, CODEC_ID_QDRAW, "QuickDraw (ffmpeg)"},
267
{BUF_VIDEO_QPEG, CODEC_ID_QPEG, "Q-Team QPEG (ffmpeg)"},
268
{BUF_VIDEO_TSCC, CODEC_ID_TSCC, "TechSmith Video (ffmpeg)"},
269
{BUF_VIDEO_ULTI, CODEC_ID_ULTI, "IBM UltiMotion (ffmpeg)"},
270
{BUF_VIDEO_WNV1, CODEC_ID_WNV1, "Winnow Video (ffmpeg)"},
271
{BUF_VIDEO_XL, CODEC_ID_VIXL, "Miro/Pinnacle VideoXL (ffmpeg)"},
272
{BUF_VIDEO_RT21, CODEC_ID_INDEO2, "Indeo/RealTime 2 (ffmpeg)"},
273
{BUF_VIDEO_FPS1, CODEC_ID_FRAPS, "Fraps (ffmpeg)"},
274
{BUF_VIDEO_MPEG, CODEC_ID_MPEG1VIDEO, "MPEG 1/2 (ffmpeg)"} };
277
static void init_video_codec (ff_video_decoder_t *this, int codec_type) {
280
/* find the decoder */
283
for(i = 0; i < sizeof(ff_video_lookup)/sizeof(ff_codec_t); i++)
284
if(ff_video_lookup[i].type == codec_type) {
285
pthread_mutex_lock(&ffmpeg_lock);
286
this->codec = avcodec_find_decoder(ff_video_lookup[i].id);
287
pthread_mutex_unlock(&ffmpeg_lock);
288
_x_meta_info_set_utf8(this->stream, XINE_META_INFO_VIDEOCODEC,
289
ff_video_lookup[i].name);
294
xprintf (this->stream->xine, XINE_VERBOSITY_LOG,
295
_("ffmpeg_video_dec: couldn't find ffmpeg decoder for buf type 0x%X\n"),
297
_x_stream_info_set(this->stream, XINE_STREAM_INFO_VIDEO_HANDLED, 0);
301
lprintf("lavc decoder found\n");
206
303
/* force (width % 8 == 0), otherwise there will be
207
304
* display problems with Xv.
662
static const ff_codec_t ff_video_lookup[] = {
663
{BUF_VIDEO_MSMPEG4_V1, CODEC_ID_MSMPEG4V1, "Microsoft MPEG-4 v1 (ffmpeg)"},
664
{BUF_VIDEO_MSMPEG4_V2, CODEC_ID_MSMPEG4V2, "Microsoft MPEG-4 v2 (ffmpeg)"},
665
{BUF_VIDEO_MSMPEG4_V3, CODEC_ID_MSMPEG4V3, "Microsoft MPEG-4 v3 (ffmpeg)"},
666
{BUF_VIDEO_WMV7, CODEC_ID_WMV1, "MS Windows Media Video 7 (ffmpeg)"},
667
{BUF_VIDEO_WMV8, CODEC_ID_WMV2, "MS Windows Media Video 8 (ffmpeg)"},
668
{BUF_VIDEO_MPEG4, CODEC_ID_MPEG4, "ISO MPEG-4 (ffmpeg)"},
669
{BUF_VIDEO_XVID, CODEC_ID_MPEG4, "ISO MPEG-4 (XviD, ffmpeg)"},
670
{BUF_VIDEO_DIVX5, CODEC_ID_MPEG4, "ISO MPEG-4 (DivX5, ffmpeg)"},
671
{BUF_VIDEO_3IVX, CODEC_ID_MPEG4, "ISO MPEG-4 (3ivx, ffmpeg)"},
672
{BUF_VIDEO_JPEG, CODEC_ID_MJPEG, "Motion JPEG (ffmpeg)"},
673
{BUF_VIDEO_MJPEG, CODEC_ID_MJPEG, "Motion JPEG (ffmpeg)"},
674
{BUF_VIDEO_MJPEG_B, CODEC_ID_MJPEGB, "Motion JPEG B (ffmpeg"},
675
{BUF_VIDEO_I263, CODEC_ID_H263I, "ITU H.263 (ffmpeg)"},
676
{BUF_VIDEO_H263, CODEC_ID_H263, "H.263 (ffmpeg)"},
677
{BUF_VIDEO_RV10, CODEC_ID_RV10, "Real Video 1.0 (ffmpeg)"},
678
{BUF_VIDEO_RV20, CODEC_ID_RV20, "Real Video 2.0 (ffmpeg)"},
679
{BUF_VIDEO_IV31, CODEC_ID_INDEO3, "Indeo Video 3.1 (ffmpeg)"},
680
{BUF_VIDEO_IV32, CODEC_ID_INDEO3, "Indeo Video 3.2 (ffmpeg)"},
681
{BUF_VIDEO_SORENSON_V1, CODEC_ID_SVQ1, "Sorenson Video 1 (ffmpeg)"},
682
{BUF_VIDEO_SORENSON_V3, CODEC_ID_SVQ3, "Sorenson Video 3 (ffmpeg)"},
683
{BUF_VIDEO_DV, CODEC_ID_DVVIDEO, "DV (ffmpeg)"},
684
{BUF_VIDEO_HUFFYUV, CODEC_ID_HUFFYUV, "HuffYUV (ffmpeg)"},
685
{BUF_VIDEO_VP31, CODEC_ID_VP3, "On2 VP3.1 (ffmpeg)"},
686
{BUF_VIDEO_4XM, CODEC_ID_4XM, "4X Video (ffmpeg)"},
687
{BUF_VIDEO_CINEPAK, CODEC_ID_CINEPAK, "Cinepak (ffmpeg)"},
688
{BUF_VIDEO_MSVC, CODEC_ID_MSVIDEO1, "Microsoft Video 1 (ffmpeg)"},
689
{BUF_VIDEO_MSRLE, CODEC_ID_MSRLE, "Microsoft RLE (ffmpeg)"},
690
{BUF_VIDEO_RPZA, CODEC_ID_RPZA, "Apple Quicktime Video/RPZA (ffmpeg)"},
691
{BUF_VIDEO_CYUV, CODEC_ID_CYUV, "Creative YUV (ffmpeg)"},
692
{BUF_VIDEO_ROQ, CODEC_ID_ROQ, "Id Software RoQ (ffmpeg)"},
693
{BUF_VIDEO_IDCIN, CODEC_ID_IDCIN, "Id Software CIN (ffmpeg)"},
694
{BUF_VIDEO_WC3, CODEC_ID_XAN_WC3, "Xan (ffmpeg)"},
695
{BUF_VIDEO_VQA, CODEC_ID_WS_VQA, "Westwood Studios VQA (ffmpeg)"},
696
{BUF_VIDEO_INTERPLAY, CODEC_ID_INTERPLAY_VIDEO, "Interplay MVE (ffmpeg)"},
697
{BUF_VIDEO_FLI, CODEC_ID_FLIC, "FLIC Video (ffmpeg)"},
698
{BUF_VIDEO_8BPS, CODEC_ID_8BPS, "Planar RGB (ffmpeg)"},
699
{BUF_VIDEO_SMC, CODEC_ID_SMC, "Apple Quicktime Graphics/SMC (ffmpeg)"},
700
{BUF_VIDEO_DUCKTM1, CODEC_ID_TRUEMOTION1,"Duck TrueMotion v1 (ffmpeg)"},
701
{BUF_VIDEO_VMD, CODEC_ID_VMDVIDEO, "Sierra VMD Video (ffmpeg)"},
702
{BUF_VIDEO_ZLIB, CODEC_ID_ZLIB, "ZLIB Video (ffmpeg)"},
703
{BUF_VIDEO_MSZH, CODEC_ID_MSZH, "MSZH Video (ffmpeg)"},
704
{BUF_VIDEO_ASV1, CODEC_ID_ASV1, "ASV v1 Video (ffmpeg)"},
705
{BUF_VIDEO_ASV2, CODEC_ID_ASV2, "ASV v2 Video (ffmpeg)"},
706
{BUF_VIDEO_ATIVCR1, CODEC_ID_VCR1, "ATI VCR-1 (ffmpeg)"},
707
{BUF_VIDEO_FLV1, CODEC_ID_FLV1, "Flash Video (ffmpeg)"},
708
{BUF_VIDEO_QTRLE, CODEC_ID_QTRLE, "Apple Quicktime Animation/RLE (ffmpeg)"},
709
{BUF_VIDEO_H264, CODEC_ID_H264, "H.264/AVC (ffmpeg)"} };
711
774
static void ff_check_bufsize (ff_video_decoder_t *this, int size) {
712
775
if (size > this->bufsize) {
713
776
this->bufsize = size + size / 2;
714
777
xprintf(this->stream->xine, XINE_VERBOSITY_LOG,
715
778
_("ffmpeg_video_dec: increasing buffer to %d to avoid overflow.\n"),
717
this->buf = realloc(this->buf, this->bufsize + FF_INPUT_BUFFER_PADDING_SIZE);
780
this->buf = realloc(this->buf, this->bufsize);
721
static void ff_decode_data (video_decoder_t *this_gen, buf_element_t *buf) {
722
ff_video_decoder_t *this = (ff_video_decoder_t *) this_gen;
724
uint8_t *ffbuf = this->buf;
725
AVRational avr00 = {0, 0};
728
lprintf ("processing packet type = %08x, len = %d, decoder_flags=%08x\n",
729
buf->type, buf->size, buf->decoder_flags);
784
static void ff_handle_preview_buffer (ff_video_decoder_t *this, buf_element_t *buf) {
787
lprintf ("preview buffer\n");
731
789
codec_type = buf->type & 0xFFFF0000;
732
790
if (codec_type == BUF_VIDEO_MPEG)
733
791
this->is_mpeg12 = 1;
735
if (buf->decoder_flags & BUF_FLAG_PREVIEW) {
737
lprintf ("preview\n");
793
if (this->decoder_init_mode && !this->is_mpeg12) {
794
init_video_codec(this, codec_type);
795
init_postprocess(this);
796
this->decoder_init_mode = 0;
741
if ( (buf->decoder_flags & BUF_FLAG_HEADER) &&
742
!(buf->decoder_flags & BUF_FLAG_SPECIAL) ) {
744
lprintf ("header\n");
749
for(i = 0; i < sizeof(ff_video_lookup)/sizeof(ff_codec_t); i++)
750
if(ff_video_lookup[i].type == codec_type) {
751
this->codec = avcodec_find_decoder(ff_video_lookup[i].id);
752
_x_meta_info_set_utf8(this->stream, XINE_META_INFO_VIDEOCODEC,
753
ff_video_lookup[i].name);
758
xprintf (this->stream->xine, XINE_VERBOSITY_LOG,
759
_("ffmpeg_video_dec: couldn't find ffmpeg decoder for buf type 0x%X\n"),
761
_x_stream_info_set(this->stream, XINE_STREAM_INFO_VIDEO_HANDLED, 0);
800
static void ff_handle_header_buffer (ff_video_decoder_t *this, buf_element_t *buf) {
802
lprintf ("header buffer\n");
804
/* accumulate data */
805
ff_check_bufsize(this, this->size + buf->size + FF_INPUT_BUFFER_PADDING_SIZE);
806
xine_fast_memcpy (&this->buf[this->size], buf->content, buf->size);
807
this->size += buf->size;
809
if (buf->decoder_flags & BUF_FLAG_FRAME_END) {
812
lprintf ("header complete\n");
813
codec_type = buf->type & 0xFFFF0000;
765
815
if (buf->decoder_flags & BUF_FLAG_STDHEADER) {
817
lprintf("standard header\n");
767
819
/* init package containing bih */
768
memcpy ( &this->bih, buf->content, sizeof(xine_bmiheader) );
820
memcpy ( &this->bih, this->buf, sizeof(xine_bmiheader) );
770
822
if (this->bih.biSize > sizeof(xine_bmiheader)) {
771
823
this->context->extradata_size = this->bih.biSize - sizeof(xine_bmiheader);
772
824
this->context->extradata = malloc(this->context->extradata_size +
773
825
FF_INPUT_BUFFER_PADDING_SIZE);
774
memcpy(this->context->extradata, buf->content + sizeof(xine_bmiheader),
775
this->context->extradata_size);
826
memcpy(this->context->extradata, this->buf + sizeof(xine_bmiheader),
827
this->context->extradata_size);
778
830
this->context->bits_per_sample = this->bih.biBitCount;
800
init_postprocess(this);
802
} else if (buf->decoder_flags & BUF_FLAG_SPECIAL) {
804
/* take care of all the various types of special buffers
805
* note that order is important here */
806
lprintf("BUF_FLAG_SPECIAL\n");
807
if (buf->decoder_info[1] == BUF_SPECIAL_STSD_ATOM &&
808
!this->context->extradata_size) {
810
lprintf("BUF_SPECIAL_STSD_ATOM\n");
811
this->context->extradata_size = buf->decoder_info[2];
812
this->context->extradata = xine_xmalloc(buf->decoder_info[2] +
813
FF_INPUT_BUFFER_PADDING_SIZE);
814
memcpy(this->context->extradata, buf->decoder_info_ptr[2],
815
buf->decoder_info[2]);
817
} else if (buf->decoder_info[1] == BUF_SPECIAL_DECODER_CONFIG &&
818
!this->context->extradata_size) {
820
lprintf("BUF_SPECIAL_DECODER_CONFIG\n");
821
this->context->extradata_size = buf->decoder_info[2];
822
this->context->extradata = xine_xmalloc(buf->decoder_info[2] +
823
FF_INPUT_BUFFER_PADDING_SIZE);
824
memcpy(this->context->extradata, buf->decoder_info_ptr[2],
825
buf->decoder_info[2]);
827
} else if (buf->decoder_info[1] == BUF_SPECIAL_PALETTE) {
829
palette_entry_t *demuxer_palette;
830
AVPaletteControl *decoder_palette;
832
lprintf("BUF_SPECIAL_PALETTE\n");
833
decoder_palette = (AVPaletteControl *)this->context->palctrl;
834
demuxer_palette = (palette_entry_t *)buf->decoder_info_ptr[2];
836
for (i = 0; i < buf->decoder_info[2]; i++) {
837
decoder_palette->palette[i] =
838
(demuxer_palette[i].r << 16) |
839
(demuxer_palette[i].g << 8) |
840
(demuxer_palette[i].b << 0);
842
decoder_palette->palette_changed = 1;
844
} else if (buf->decoder_info[1] == BUF_SPECIAL_RV_CHUNK_TABLE) {
846
lprintf("BUF_SPECIAL_RV_CHUNK_TABLE\n");
847
this->context->slice_count = buf->decoder_info[2]+1;
849
if(this->context->slice_count > this->slice_offset_size) {
850
this->context->slice_offset = realloc(this->context->slice_offset,
851
sizeof(int)*this->context->slice_count);
852
this->slice_offset_size = this->context->slice_count;
855
for(i = 0; i < this->context->slice_count; i++)
856
this->context->slice_offset[i] =
857
((uint32_t *) buf->decoder_info_ptr[2])[(2*i)+1];
860
return; /* do not send special data to the decoder */
863
if (((this->size == 0) && (buf->decoder_flags & BUF_FLAG_FRAME_END) &&
864
((buf->size + FF_INPUT_BUFFER_PADDING_SIZE) < buf->max_size)) ||
866
/* buf contains a full frame */
855
/* reset accumulator */
860
static void ff_handle_special_buffer (ff_video_decoder_t *this, buf_element_t *buf) {
863
/* take care of all the various types of special buffers
864
* note that order is important here */
865
lprintf("special buffer\n");
867
if (buf->decoder_info[1] == BUF_SPECIAL_STSD_ATOM &&
868
!this->context->extradata_size) {
870
lprintf("BUF_SPECIAL_STSD_ATOM\n");
871
this->context->extradata_size = buf->decoder_info[2];
872
this->context->extradata = xine_xmalloc(buf->decoder_info[2] +
873
FF_INPUT_BUFFER_PADDING_SIZE);
874
memcpy(this->context->extradata, buf->decoder_info_ptr[2],
875
buf->decoder_info[2]);
877
} else if (buf->decoder_info[1] == BUF_SPECIAL_DECODER_CONFIG &&
878
!this->context->extradata_size) {
880
lprintf("BUF_SPECIAL_DECODER_CONFIG\n");
881
this->context->extradata_size = buf->decoder_info[2];
882
this->context->extradata = xine_xmalloc(buf->decoder_info[2] +
883
FF_INPUT_BUFFER_PADDING_SIZE);
884
memcpy(this->context->extradata, buf->decoder_info_ptr[2],
885
buf->decoder_info[2]);
887
} else if (buf->decoder_info[1] == BUF_SPECIAL_PALETTE) {
889
palette_entry_t *demuxer_palette;
890
AVPaletteControl *decoder_palette;
892
lprintf("BUF_SPECIAL_PALETTE\n");
893
this->context->palctrl = &this->palette_control;
894
decoder_palette = (AVPaletteControl *)this->context->palctrl;
895
demuxer_palette = (palette_entry_t *)buf->decoder_info_ptr[2];
897
for (i = 0; i < buf->decoder_info[2]; i++) {
898
decoder_palette->palette[i] =
899
(demuxer_palette[i].r << 16) |
900
(demuxer_palette[i].g << 8) |
901
(demuxer_palette[i].b << 0);
903
decoder_palette->palette_changed = 1;
905
} else if (buf->decoder_info[1] == BUF_SPECIAL_RV_CHUNK_TABLE) {
907
lprintf("BUF_SPECIAL_RV_CHUNK_TABLE\n");
908
this->context->slice_count = buf->decoder_info[2]+1;
910
lprintf("slice_count=%d\n", this->context->slice_count);
912
if(this->context->slice_count > this->slice_offset_size) {
913
this->context->slice_offset = realloc(this->context->slice_offset,
914
sizeof(int)*this->context->slice_count);
915
this->slice_offset_size = this->context->slice_count;
918
for(i = 0; i < this->context->slice_count; i++) {
919
this->context->slice_offset[i] =
920
((uint32_t *) buf->decoder_info_ptr[2])[(2*i)+1];
921
lprintf("slice_offset[%d]=%d\n", i, this->context->slice_offset[i]);
926
static void ff_handle_mpeg12_buffer (ff_video_decoder_t *this, buf_element_t *buf) {
930
int got_picture, len;
933
int size = buf->size;
935
lprintf("handle_mpeg12_buffer\n");
937
while ((size > 0) || (flush == 1)) {
944
current = mpeg_parser_decode_data(&this->mpeg_parser,
945
buf->content + offset, buf->content + offset + size,
948
current = buf->content + offset + size; /* end of the buffer */
951
if (current == NULL) {
952
lprintf("current == NULL\n");
956
if (this->mpeg_parser.has_sequence) {
957
ff_handle_mpeg_sequence(this, &this->mpeg_parser);
960
if (!this->decoder_ok)
964
lprintf("flush lavc buffers\n");
965
/* hack: ffmpeg outputs the last frame if size=0 */
966
this->mpeg_parser.buffer_size = 0;
969
/* skip decoding b frames if too late */
970
this->context->hurry_up = (this->skipframes > 0);
972
lprintf("avcodec_decode_video: size=%d\n", this->mpeg_parser.buffer_size);
973
len = avcodec_decode_video (this->context, this->av_frame,
974
&got_picture, this->mpeg_parser.chunk_buffer,
975
this->mpeg_parser.buffer_size);
976
lprintf("avcodec_decode_video: decoded_size=%d, got_picture=%d\n",
978
len = current - buf->content - offset;
979
lprintf("avcodec_decode_video: consumed_size=%d\n", len);
983
if ((len < 0) || (len > buf->size)) {
984
xprintf (this->stream->xine, XINE_VERBOSITY_DEBUG,
985
"ffmpeg_video_dec: error decompressing frame\n");
986
size = 0; /* draw a bad frame and exit */
992
if (got_picture && this->av_frame->data[0]) {
993
/* got a picture, draw it */
994
if(!this->av_frame->opaque) {
995
/* indirect rendering */
996
img = this->stream->video_out->get_frame (this->stream->video_out,
1000
this->output_format,
1001
VO_BOTH_FIELDS|this->frame_flags);
1005
img = (vo_frame_t*) this->av_frame->opaque;
1009
img->pts = this->pts;
1012
if (this->av_frame->repeat_pict)
1013
img->duration = this->video_step * 3 / 2;
1015
img->duration = this->video_step;
1017
img->crop_right = this->crop_right;
1018
img->crop_bottom = this->crop_bottom;
1020
this->skipframes = img->draw(img, this->stream);
1027
if (this->context->hurry_up) {
1028
/* skipped frame, output a bad frame */
1029
img = this->stream->video_out->get_frame (this->stream->video_out,
1033
this->output_format,
1034
VO_BOTH_FIELDS|this->frame_flags);
1036
img->duration = this->video_step;
1038
this->skipframes = img->draw(img, this->stream);
1045
static void ff_handle_buffer (ff_video_decoder_t *this, buf_element_t *buf) {
1046
uint8_t *chunk_buf = this->buf;
1047
AVRational avr00 = {0, 1};
1049
lprintf("handle_buffer\n");
1051
if (!this->decoder_ok) {
1052
if (this->decoder_init_mode) {
1053
int codec_type = buf->type & 0xFFFF0000;
1055
/* init ffmpeg decoder */
1056
init_video_codec(this, codec_type);
1057
init_postprocess(this);
1058
this->decoder_init_mode = 0;
1064
if (buf->decoder_flags & BUF_FLAG_FRAME_START) {
1065
lprintf("BUF_FLAG_FRAME_START\n");
1069
/* data accumulation */
1070
if (buf->size > 0) {
1071
if ((this->size == 0) &&
1072
((buf->size + FF_INPUT_BUFFER_PADDING_SIZE) < buf->max_size) &&
1073
(buf->decoder_flags & BUF_FLAG_FRAME_END)) {
1074
/* buf contains a complete frame */
867
1075
/* no memcpy needed */
868
ffbuf = buf->content;
1076
chunk_buf = buf->content;
869
1077
this->size = buf->size;
870
1078
lprintf("no memcpy needed to accumulate data\n");
872
ff_check_bufsize(this, this->size + buf->size);
873
ffbuf = this->buf; /* ff_check_bufsize can realloc this->buf */
1080
/* copy data into our internal buffer */
1081
ff_check_bufsize(this, this->size + buf->size + FF_INPUT_BUFFER_PADDING_SIZE);
1082
chunk_buf = this->buf; /* ff_check_bufsize might realloc this->buf */
874
1084
xine_fast_memcpy (&this->buf[this->size], buf->content, buf->size);
875
1086
this->size += buf->size;
876
1087
lprintf("accumulate data into this->buf\n");
880
if (buf->decoder_flags & BUF_FLAG_FRAMERATE) {
881
this->video_step = buf->decoder_info[0];
882
_x_stream_info_set(this->stream, XINE_STREAM_INFO_FRAME_DURATION, this->video_step);
885
if (buf->decoder_flags & BUF_FLAG_ASPECT) {
886
this->aspect_ratio = (double)buf->decoder_info[1] / (double)buf->decoder_info[2];
887
_x_stream_info_set(this->stream, XINE_STREAM_INFO_VIDEO_RATIO,
888
this->aspect_ratio*10000);
892
this->pts = buf->pts;
894
if (this->size || this->is_mpeg12) {
896
if (!this->decoder_ok && !this->is_mpeg12 &&
897
(_x_stream_info_get(this->stream, XINE_STREAM_INFO_VIDEO_HANDLED) != 0)) {
898
init_video_codec(this);
901
if (this->is_mpeg12 ||
902
(this->decoder_ok && (buf->decoder_flags & BUF_FLAG_FRAME_END))) {
906
int got_picture, len;
910
/* decode video frame(s) */
913
/* flag for interlaced streams */
914
this->frame_flags = 0;
915
/* FIXME: which codecs can be interlaced?
916
FIXME: check interlaced DCT and other codec specific info. */
917
switch( codec_type ) {
919
this->frame_flags |= VO_INTERLACED_FLAG;
922
this->frame_flags |= VO_INTERLACED_FLAG;
924
case BUF_VIDEO_MJPEG:
925
this->frame_flags |= VO_INTERLACED_FLAG;
927
case BUF_VIDEO_HUFFYUV:
928
this->frame_flags |= VO_INTERLACED_FLAG;
932
/* skip decoding b frames if too late */
933
this->context->hurry_up = (this->skipframes > 0);
936
ffbuf[this->size] = 0;
1091
if (buf->decoder_flags & BUF_FLAG_FRAME_END) {
1095
int got_picture, len;
1096
int got_one_picture = 0;
1098
int codec_type = buf->type & 0xFFFF0000;
1100
/* pad input data */
1101
chunk_buf[this->size] = 0;
1103
while (this->size > 0) {
939
while ((this->size > 0) || (flush == 1)){
941
/* DV frames can be completely skipped */
942
if( codec_type == BUF_VIDEO_DV && this->skipframes ) {
947
if (this->is_mpeg12) {
953
current = mpeg_parser_decode_data(&this->mpeg_parser,
954
ffbuf + offset, ffbuf + offset + this->size,
957
current = ffbuf + offset + this->size; /* end of the buffer */
960
if (current == NULL) {
961
lprintf("current == NULL\n");
965
if (this->mpeg_parser.has_sequence) {
966
ff_handle_mpeg_sequence(this, &this->mpeg_parser);
970
lprintf("flush lavc buffers\n");
971
/* hack: ffmpeg outputs the last frame if size=0 */
972
this->mpeg_parser.buffer_size = 0;
974
lprintf("avcodec_decode_video: size=%d\n", this->mpeg_parser.buffer_size);
975
len = avcodec_decode_video (this->context, this->av_frame,
976
&got_picture, this->mpeg_parser.chunk_buffer,
977
this->mpeg_parser.buffer_size);
978
lprintf("avcodec_decode_video: decoded_size=%d, got_picture=%d\n",
980
len = current - ffbuf - offset;
981
lprintf("avcodec_decode_video: consumed_size=%d\n", len);
987
len = avcodec_decode_video (this->context, this->av_frame,
988
&got_picture, &ffbuf[offset],
992
if ((len < 0) || (len > this->size)) {
1105
/* DV frames can be completely skipped */
1106
if( codec_type == BUF_VIDEO_DV && this->skipframes ) {
1110
/* skip decoding b frames if too late */
1111
this->context->hurry_up = (this->skipframes > 0);
1113
lprintf("buffer size: %d\n", this->size);
1114
len = avcodec_decode_video (this->context, this->av_frame,
1115
&got_picture, &chunk_buf[offset],
1117
lprintf("consumed size: %d, got_picture: %d\n", len, got_picture);
1118
if ((len <= 0) || (len > this->size)) {
993
1119
xprintf (this->stream->xine, XINE_VERBOSITY_DEBUG,
994
"ffmpeg_video_dec: error decompressing frame\n");
1120
"ffmpeg_video_dec: error decompressing frame\n");
1002
if(!this->bih.biWidth || !this->bih.biHeight) {
1003
this->bih.biWidth = this->context->width;
1004
this->bih.biHeight = this->context->height;
1005
this->aspect_ratio = (double)this->bih.biWidth / (double)this->bih.biHeight;
1006
set_stream_info(this);
1009
if (!got_picture || !this->av_frame->data[0]) {
1010
xprintf(this->stream->xine, XINE_VERBOSITY_DEBUG,
1011
"ffmpeg_video_dec: didn't get a picture, %d bytes left\n",
1014
if (!this->is_mpeg12) {
1015
if (this->size > 0) {
1016
ff_check_bufsize(this, offset + this->size);
1017
memmove (this->buf, &ffbuf[offset], this->size);
1022
if (this->context->hurry_up) {
1023
/* skipped frame, output a bad frame */
1024
img = this->stream->video_out->get_frame (this->stream->video_out,
1028
this->output_format,
1029
VO_BOTH_FIELDS|this->frame_flags);
1031
img->duration = this->video_step;
1033
this->skipframes = img->draw(img, this->stream);
1128
if (this->size > 0) {
1129
ff_check_bufsize(this, this->size + FF_INPUT_BUFFER_PADDING_SIZE);
1130
memmove (this->buf, &chunk_buf[offset], this->size);
1131
chunk_buf = this->buf;
1040
lprintf ("got a picture\n");
1042
if(av_cmp_q(this->context->sample_aspect_ratio, avr00)) {
1043
this->aspect_ratio = av_q2d(this->context->sample_aspect_ratio) *
1044
(double)this->bih.biWidth / (double)this->bih.biHeight;
1045
_x_stream_info_set(this->stream, XINE_STREAM_INFO_VIDEO_RATIO,
1046
this->aspect_ratio*10000);
1136
/* aspect ratio provided by ffmpeg, override previous setting */
1137
if ((this->aspect_ratio_prio < 2) &&
1138
av_cmp_q(this->context->sample_aspect_ratio, avr00)) {
1140
this->aspect_ratio = av_q2d(this->context->sample_aspect_ratio) *
1141
(double)this->bih.biWidth / (double)this->bih.biHeight;
1142
this->aspect_ratio_prio = 2;
1143
lprintf("ffmpeg aspect ratio: %f\n", this->aspect_ratio);
1144
set_stream_info(this);
1147
if (got_picture && this->av_frame->data[0]) {
1148
/* got a picture, draw it */
1149
got_one_picture = 1;
1049
1150
if(!this->av_frame->opaque) {
1151
/* indirect rendering */
1153
/* initialize the colorspace converter */
1154
if (!this->cs_convert_init) {
1155
if ((this->context->pix_fmt == PIX_FMT_RGBA32) ||
1156
(this->context->pix_fmt == PIX_FMT_RGB565) ||
1157
(this->context->pix_fmt == PIX_FMT_RGB555) ||
1158
(this->context->pix_fmt == PIX_FMT_BGR24) ||
1159
(this->context->pix_fmt == PIX_FMT_RGB24) ||
1160
(this->context->pix_fmt == PIX_FMT_PAL8)) {
1161
this->output_format = XINE_IMGFMT_YUY2;
1162
init_yuv_planes(&this->yuv, this->bih.biWidth, this->bih.biHeight);
1165
this->cs_convert_init = 1;
1168
if (this->aspect_ratio_prio == 0) {
1169
this->aspect_ratio = (double)this->bih.biWidth / (double)this->bih.biHeight;
1170
this->aspect_ratio_prio = 1;
1171
lprintf("default aspect ratio: %f\n", this->aspect_ratio);
1172
set_stream_info(this);
1050
1175
img = this->stream->video_out->get_frame (this->stream->video_out,
1051
1176
this->bih.biWidth,
1052
1177
this->bih.biHeight,
1055
1180
VO_BOTH_FIELDS|this->frame_flags);
1058
1184
img = (vo_frame_t*) this->av_frame->opaque;
1063
xprintf (this->stream->xine, XINE_VERBOSITY_DEBUG,
1064
"ffmpeg_video_dec: error decompressing frame\n");
1069
if(this->pp_quality != this->class->pp_quality)
1070
pp_change_quality(this);
1072
if(this->pp_available && this->pp_quality) {
1074
if(this->av_frame->opaque) {
1075
img = this->stream->video_out->get_frame (this->stream->video_out,
1079
this->output_format,
1080
VO_BOTH_FIELDS|this->frame_flags);
1085
pp_postprocess(this->av_frame->data, this->av_frame->linesize,
1086
img->base, img->pitches,
1087
img->width, img->height,
1088
this->av_frame->qscale_table, this->av_frame->qstride,
1089
this->pp_mode, this->pp_context,
1090
this->av_frame->pict_type);
1092
} else if(!this->av_frame->opaque) {
1093
ff_convert_frame(this, img);
1188
/* post processing */
1189
if(this->pp_quality != this->class->pp_quality)
1190
pp_change_quality(this);
1192
if(this->pp_available && this->pp_quality) {
1194
if(this->av_frame->opaque) {
1196
img = this->stream->video_out->get_frame (this->stream->video_out,
1200
this->output_format,
1201
VO_BOTH_FIELDS|this->frame_flags);
1205
pp_postprocess(this->av_frame->data, this->av_frame->linesize,
1206
img->base, img->pitches,
1207
img->width, img->height,
1208
this->av_frame->qscale_table, this->av_frame->qstride,
1209
this->pp_mode, this->pp_context,
1210
this->av_frame->pict_type);
1212
} else if (!this->av_frame->opaque) {
1213
/* colorspace conversion or copy */
1214
ff_convert_frame(this, img);
1097
img->pts = this->pts;
1217
img->pts = this->pts;
1100
1220
/* workaround for weird 120fps streams */
1101
1221
if( this->video_step == 750 ) {
1103
/* use ffmpeg frame rate if available. i'm unsure if ffmpeg
1104
* really knows it better than what demux told us.
1106
if( this->context->frame_rate && this->context->frame_rate_base )
1107
this->video_step = 90000 * this->context->frame_rate_base /
1108
this->context->frame_rate;
1111
/* fallback to the VIDEO_PTS_MODE */
1112
this->video_step = 0;
1222
/* fallback to the VIDEO_PTS_MODE */
1223
this->video_step = 0;
1115
if (!this->av_frame->repeat_pict)
1226
if (this->av_frame->repeat_pict)
1227
img->duration = this->video_step * 3 / 2;
1116
1229
img->duration = this->video_step;
1118
img->duration = this->video_step * 3 / 2;
1120
1231
img->crop_right = this->crop_right;
1121
1232
img->crop_bottom = this->crop_bottom;
1123
1234
this->skipframes = img->draw(img, this->stream);
1124
if( this->skipframes < 0 )
1125
this->skipframes = 0;
1128
1237
img->free(img);
1241
if (!got_one_picture) {
1242
/* skipped frame, output a bad frame */
1243
img = this->stream->video_out->get_frame (this->stream->video_out,
1247
this->output_format,
1248
VO_BOTH_FIELDS|this->frame_flags);
1250
img->duration = this->video_step;
1252
this->skipframes = img->draw(img, this->stream);
1258
static void ff_decode_data (video_decoder_t *this_gen, buf_element_t *buf) {
1259
ff_video_decoder_t *this = (ff_video_decoder_t *) this_gen;
1261
lprintf ("processing packet type = %08x, len = %d, decoder_flags=%08x\n",
1262
buf->type, buf->size, buf->decoder_flags);
1264
if (buf->decoder_flags & BUF_FLAG_FRAMERATE) {
1265
this->video_step = buf->decoder_info[0];
1266
_x_stream_info_set(this->stream, XINE_STREAM_INFO_FRAME_DURATION, this->video_step);
1269
if (buf->decoder_flags & BUF_FLAG_PREVIEW) {
1271
ff_handle_preview_buffer(this, buf);
1275
if (buf->decoder_flags & BUF_FLAG_SPECIAL) {
1277
ff_handle_special_buffer(this, buf);
1281
if (buf->decoder_flags & BUF_FLAG_HEADER) {
1283
ff_handle_header_buffer(this, buf);
1285
if (buf->decoder_flags & BUF_FLAG_ASPECT) {
1286
if (this->aspect_ratio_prio < 3) {
1287
this->aspect_ratio = (double)buf->decoder_info[1] / (double)buf->decoder_info[2];
1288
this->aspect_ratio_prio = 3;
1289
lprintf("aspect ratio: %f\n", this->aspect_ratio);
1290
set_stream_info(this);
1298
this->pts = buf->pts;
1300
if (this->is_mpeg12) {
1301
ff_handle_mpeg12_buffer(this, buf);
1303
ff_handle_buffer(this, buf);