Mercurial > libavcodec.hg
comparison dv.c @ 8131:c30bdda1adb1 libavcodec
Taking advantage of the new ->execute API
author | romansh |
---|---|
date | Wed, 12 Nov 2008 21:13:28 +0000 |
parents | a9734fe0811e |
children | e1a094cabfc3 |
comparison
equal
deleted
inserted
replaced
8130:c45366b01126 | 8131:c30bdda1adb1 |
---|---|
90 return size; | 90 return size; |
91 } | 91 } |
92 | 92 |
93 static int dv_init_dynamic_tables(const DVprofile *d) | 93 static int dv_init_dynamic_tables(const DVprofile *d) |
94 { | 94 { |
95 int j,i,c,s,p; | 95 int j,i,c,s,p,k; |
96 | 96 |
97 if (d->work_chunks[dv_work_pool_size(d)-1]) | 97 if (d->work_chunks[dv_work_pool_size(d)-1].buf_offset) |
98 return 0; | 98 return 0; |
99 | 99 |
100 p = i = 0; | 100 p = i = 0; |
101 for (c=0; c<d->n_difchan; c++) { | 101 for (c=0; c<d->n_difchan; c++) { |
102 for (s=0; s<d->difseg_size; s++) { | 102 for (s=0; s<d->difseg_size; s++) { |
103 p += 6; | 103 p += 6; |
104 for (j=0; j<27; j++) { | 104 for (j=0; j<27; j++) { |
105 p += !(j%3); | 105 p += !(j%3); |
106 if (!(DV_PROFILE_IS_1080i50(d) && c != 0 && s == 11) && | 106 if (!(DV_PROFILE_IS_1080i50(d) && c != 0 && s == 11) && |
107 !(DV_PROFILE_IS_720p50(d) && s > 9)) { | 107 !(DV_PROFILE_IS_720p50(d) && s > 9)) { |
108 d->work_chunks[i++] = (void*)(size_t)((p<<18)|(c << 16)|(s << 8)|j); | 108 for (k=0; k<5; k++) |
109 d->work_chunks[i].mb_coordinates[k] = d->video_place[(c*d->difseg_size+s)*27*5 + j*5 + k]; | |
110 d->work_chunks[i++].buf_offset = p; | |
109 } | 111 } |
110 p += 5; | 112 p += 5; |
111 } | 113 } |
112 } | 114 } |
113 } | 115 } |
379 if (bits_left > 0) { | 381 if (bits_left > 0) { |
380 put_bits(pb, bits_left, get_bits(gb, bits_left)); | 382 put_bits(pb, bits_left, get_bits(gb, bits_left)); |
381 } | 383 } |
382 } | 384 } |
383 | 385 |
384 static inline void dv_calculate_mb_xy(DVVideoContext *s, int work_chunk, int m, int *mb_x, int *mb_y) | 386 static inline void dv_calculate_mb_xy(DVVideoContext *s, DVwork_chunk *work_chunk, int m, int *mb_x, int *mb_y) |
385 { | 387 { |
386 int i, chan, seg, slot; | 388 *mb_x = work_chunk->mb_coordinates[m] & 0xff; |
387 | 389 *mb_y = work_chunk->mb_coordinates[m] >> 8; |
388 chan = (work_chunk>>16)&0x03; | |
389 seg = (work_chunk>>8)&0xff; | |
390 slot = (work_chunk)&0xff; | |
391 | |
392 i = (chan*s->sys->difseg_size+seg)*27*5 + slot*5 + m; | |
393 *mb_x = s->sys->video_place[i] & 0xff; | |
394 *mb_y = s->sys->video_place[i] >> 8; | |
395 | 390 |
396 /* We work with 720p frames split in half. The odd half-frame (chan==2,3) is displaced :-( */ | 391 /* We work with 720p frames split in half. The odd half-frame (chan==2,3) is displaced :-( */ |
397 if (s->sys->height == 720 && !(s->buf[1]&0x0C)) { | 392 if (s->sys->height == 720 && !(s->buf[1]&0x0C)) { |
398 *mb_y -= (*mb_y>17)?18:-72; /* shifting the Y coordinate down by 72/2 macro blocks */ | 393 *mb_y -= (*mb_y>17)?18:-72; /* shifting the Y coordinate down by 72/2 macro blocks */ |
399 } | 394 } |
400 } | 395 } |
401 | 396 |
402 /* mb_x and mb_y are in units of 8 pixels */ | 397 /* mb_x and mb_y are in units of 8 pixels */ |
403 static inline void dv_decode_video_segment(DVVideoContext *s, int work_chunk) | 398 static inline void dv_decode_video_segment(DVVideoContext *s, DVwork_chunk *work_chunk) |
404 { | 399 { |
405 int quant, dc, dct_mode, class1, j; | 400 int quant, dc, dct_mode, class1, j; |
406 int mb_index, mb_x, mb_y, last_index; | 401 int mb_index, mb_x, mb_y, last_index; |
407 int y_stride, linesize; | 402 int y_stride, linesize; |
408 DCTELEM *block, *block1; | 403 DCTELEM *block, *block1; |
422 assert((((int)vs_bit_buffer) & 7) == 0); | 417 assert((((int)vs_bit_buffer) & 7) == 0); |
423 | 418 |
424 memset(sblock, 0, sizeof(sblock)); | 419 memset(sblock, 0, sizeof(sblock)); |
425 | 420 |
426 /* pass 1 : read DC and AC coefficients in blocks */ | 421 /* pass 1 : read DC and AC coefficients in blocks */ |
427 buf_ptr = &s->buf[(work_chunk>>18)*80]; | 422 buf_ptr = &s->buf[work_chunk->buf_offset*80]; |
428 block1 = &sblock[0][0]; | 423 block1 = &sblock[0][0]; |
429 mb1 = mb_data; | 424 mb1 = mb_data; |
430 init_put_bits(&vs_pb, vs_bit_buffer, 5 * 80); | 425 init_put_bits(&vs_pb, vs_bit_buffer, 5 * 80); |
431 for (mb_index = 0; mb_index < 5; mb_index++, mb1 += s->sys->bpm, block1 += s->sys->bpm * 64) { | 426 for (mb_index = 0; mb_index < 5; mb_index++, mb1 += s->sys->bpm, block1 += s->sys->bpm * 64) { |
432 /* skip header */ | 427 /* skip header */ |
860 } | 855 } |
861 } | 856 } |
862 } | 857 } |
863 } | 858 } |
864 | 859 |
865 static inline void dv_encode_video_segment(DVVideoContext *s, int work_chunk) | 860 static inline void dv_encode_video_segment(DVVideoContext *s, DVwork_chunk *work_chunk) |
866 { | 861 { |
867 int mb_index, i, j; | 862 int mb_index, i, j; |
868 int mb_x, mb_y, c_offset, linesize; | 863 int mb_x, mb_y, c_offset, linesize; |
869 uint8_t* y_ptr; | 864 uint8_t* y_ptr; |
870 uint8_t* data; | 865 uint8_t* data; |
879 int vs_bit_size = 0; | 874 int vs_bit_size = 0; |
880 int qnos[5]; | 875 int qnos[5]; |
881 | 876 |
882 assert((((int)block) & 15) == 0); | 877 assert((((int)block) & 15) == 0); |
883 | 878 |
884 dif = &s->buf[(work_chunk>>18)*80]; | 879 dif = &s->buf[work_chunk->buf_offset*80]; |
885 enc_blk = &enc_blks[0]; | 880 enc_blk = &enc_blks[0]; |
886 pb = &pbs[0]; | 881 pb = &pbs[0]; |
887 for (mb_index = 0; mb_index < 5; mb_index++) { | 882 for (mb_index = 0; mb_index < 5; mb_index++) { |
888 dv_calculate_mb_xy(s, work_chunk, mb_index, &mb_x, &mb_y); | 883 dv_calculate_mb_xy(s, work_chunk, mb_index, &mb_x, &mb_y); |
889 y_ptr = s->picture.data[0] + ((mb_y * s->picture.linesize[0] + mb_x) << 3); | 884 y_ptr = s->picture.data[0] + ((mb_y * s->picture.linesize[0] + mb_x) << 3); |
1011 flush_put_bits(&pbs[j]); | 1006 flush_put_bits(&pbs[j]); |
1012 } | 1007 } |
1013 | 1008 |
1014 static int dv_decode_mt(AVCodecContext *avctx, void* sl) | 1009 static int dv_decode_mt(AVCodecContext *avctx, void* sl) |
1015 { | 1010 { |
1016 dv_decode_video_segment((DVVideoContext *)avctx->priv_data, *(size_t*)sl); | 1011 dv_decode_video_segment((DVVideoContext *)avctx->priv_data, (DVwork_chunk*)sl); |
1017 return 0; | 1012 return 0; |
1018 } | 1013 } |
1019 | 1014 |
1020 #ifdef CONFIG_DVVIDEO_ENCODER | 1015 #ifdef CONFIG_DVVIDEO_ENCODER |
1021 static int dv_encode_mt(AVCodecContext *avctx, void* sl) | 1016 static int dv_encode_mt(AVCodecContext *avctx, void* sl) |
1022 { | 1017 { |
1023 dv_encode_video_segment((DVVideoContext *)avctx->priv_data, *(size_t*)sl); | 1018 dv_encode_video_segment((DVVideoContext *)avctx->priv_data, (DVwork_chunk*)sl); |
1024 return 0; | 1019 return 0; |
1025 } | 1020 } |
1026 #endif | 1021 #endif |
1027 | 1022 |
1028 #ifdef CONFIG_DVVIDEO_DECODER | 1023 #ifdef CONFIG_DVVIDEO_DECODER |
1054 s->picture.interlaced_frame = 1; | 1049 s->picture.interlaced_frame = 1; |
1055 s->picture.top_field_first = 0; | 1050 s->picture.top_field_first = 0; |
1056 | 1051 |
1057 s->buf = buf; | 1052 s->buf = buf; |
1058 avctx->execute(avctx, dv_decode_mt, s->sys->work_chunks, NULL, | 1053 avctx->execute(avctx, dv_decode_mt, s->sys->work_chunks, NULL, |
1059 dv_work_pool_size(s->sys), sizeof(void*)); | 1054 dv_work_pool_size(s->sys), sizeof(DVwork_chunk)); |
1060 | 1055 |
1061 emms_c(); | 1056 emms_c(); |
1062 | 1057 |
1063 /* return image */ | 1058 /* return image */ |
1064 *data_size = sizeof(AVFrame); | 1059 *data_size = sizeof(AVFrame); |
1207 s->picture.key_frame = 1; | 1202 s->picture.key_frame = 1; |
1208 s->picture.pict_type = FF_I_TYPE; | 1203 s->picture.pict_type = FF_I_TYPE; |
1209 | 1204 |
1210 s->buf = buf; | 1205 s->buf = buf; |
1211 c->execute(c, dv_encode_mt, s->sys->work_chunks, NULL, | 1206 c->execute(c, dv_encode_mt, s->sys->work_chunks, NULL, |
1212 dv_work_pool_size(s->sys), sizeof(void*)); | 1207 dv_work_pool_size(s->sys), sizeof(DVwork_chunk)); |
1213 | 1208 |
1214 emms_c(); | 1209 emms_c(); |
1215 | 1210 |
1216 dv_format_frame(s, buf); | 1211 dv_format_frame(s, buf); |
1217 | 1212 |