Mercurial > libavcodec.hg
comparison libdiracdec.c @ 10060:965220ebc611 libavcodec
cosmetics: indentation, prettyprinting, K&R coding style
| author | diego |
|---|---|
| date | Sat, 15 Aug 2009 11:42:15 +0000 |
| parents | 646065f63290 |
| children | 8a4984c5cacc |
comparison
equal
deleted
inserted
replaced
| 10059:c6ace59701ce | 10060:965220ebc611 |
|---|---|
| 34 #include <assert.h> | 34 #include <assert.h> |
| 35 | 35 |
| 36 #include <libdirac_decoder/dirac_parser.h> | 36 #include <libdirac_decoder/dirac_parser.h> |
| 37 | 37 |
| 38 /** contains a single frame returned from Dirac */ | 38 /** contains a single frame returned from Dirac */ |
| 39 typedef struct FfmpegDiracDecoderParams | 39 typedef struct FfmpegDiracDecoderParams { |
| 40 { | |
| 41 /** decoder handle */ | 40 /** decoder handle */ |
| 42 dirac_decoder_t* p_decoder; | 41 dirac_decoder_t* p_decoder; |
| 43 | 42 |
| 44 /** buffer to hold decoded frame */ | 43 /** buffer to hold decoded frame */ |
| 45 unsigned char* p_out_frame_buf; | 44 unsigned char* p_out_frame_buf; |
| 62 } | 61 } |
| 63 | 62 |
| 64 static av_cold int libdirac_decode_init(AVCodecContext *avccontext) | 63 static av_cold int libdirac_decode_init(AVCodecContext *avccontext) |
| 65 { | 64 { |
| 66 | 65 |
| 67 FfmpegDiracDecoderParams *p_dirac_params = avccontext->priv_data ; | 66 FfmpegDiracDecoderParams *p_dirac_params = avccontext->priv_data; |
| 68 p_dirac_params->p_decoder = dirac_decoder_init(avccontext->debug); | 67 p_dirac_params->p_decoder = dirac_decoder_init(avccontext->debug); |
| 69 | 68 |
| 70 if (!p_dirac_params->p_decoder) | 69 if (!p_dirac_params->p_decoder) |
| 71 return -1; | 70 return -1; |
| 72 | 71 |
| 73 return 0 ; | 72 return 0; |
| 74 } | 73 } |
| 75 | 74 |
| 76 static int libdirac_decode_frame(AVCodecContext *avccontext, | 75 static int libdirac_decode_frame(AVCodecContext *avccontext, |
| 77 void *data, int *data_size, | 76 void *data, int *data_size, |
| 78 AVPacket *avpkt) | 77 AVPacket *avpkt) |
| 86 int pict_size; | 85 int pict_size; |
| 87 unsigned char *buffer[3]; | 86 unsigned char *buffer[3]; |
| 88 | 87 |
| 89 *data_size = 0; | 88 *data_size = 0; |
| 90 | 89 |
| 91 if (buf_size>0) { | 90 if (buf_size > 0) { |
| 92 /* set data to decode into buffer */ | 91 /* set data to decode into buffer */ |
| 93 dirac_buffer (p_dirac_params->p_decoder, buf, buf+buf_size); | 92 dirac_buffer(p_dirac_params->p_decoder, buf, buf + buf_size); |
| 94 if ((buf[4] &0x08) == 0x08 && (buf[4] & 0x03)) | 93 if ((buf[4] & 0x08) == 0x08 && (buf[4] & 0x03)) |
| 95 avccontext->has_b_frames = 1; | 94 avccontext->has_b_frames = 1; |
| 96 } | 95 } |
| 97 while (1) { | 96 while (1) { |
| 98 /* parse data and process result */ | 97 /* parse data and process result */ |
| 99 DecoderState state = dirac_parse (p_dirac_params->p_decoder); | 98 DecoderState state = dirac_parse(p_dirac_params->p_decoder); |
| 100 switch (state) | 99 switch (state) { |
| 101 { | |
| 102 case STATE_BUFFER: | 100 case STATE_BUFFER: |
| 103 return buf_size; | 101 return buf_size; |
| 104 | 102 |
| 105 case STATE_SEQUENCE: | 103 case STATE_SEQUENCE: |
| 106 { | 104 { |
| 107 /* tell FFmpeg about sequence details */ | 105 /* tell FFmpeg about sequence details */ |
| 108 dirac_sourceparams_t *src_params = | 106 dirac_sourceparams_t *src_params = &p_dirac_params->p_decoder->src_params; |
| 109 &p_dirac_params->p_decoder->src_params; | |
| 110 | 107 |
| 111 if (avcodec_check_dimensions(avccontext, src_params->width, | 108 if (avcodec_check_dimensions(avccontext, src_params->width, |
| 112 src_params->height) < 0) { | 109 src_params->height) < 0) { |
| 113 av_log(avccontext, AV_LOG_ERROR, "Invalid dimensions (%dx%d)\n", | 110 av_log(avccontext, AV_LOG_ERROR, "Invalid dimensions (%dx%d)\n", |
| 114 src_params->width, src_params->height); | 111 src_params->width, src_params->height); |
| 119 avccontext->height = src_params->height; | 116 avccontext->height = src_params->height; |
| 120 avccontext->width = src_params->width; | 117 avccontext->width = src_params->width; |
| 121 | 118 |
| 122 avccontext->pix_fmt = GetFfmpegChromaFormat(src_params->chroma); | 119 avccontext->pix_fmt = GetFfmpegChromaFormat(src_params->chroma); |
| 123 if (avccontext->pix_fmt == PIX_FMT_NONE) { | 120 if (avccontext->pix_fmt == PIX_FMT_NONE) { |
| 124 av_log (avccontext, AV_LOG_ERROR, | 121 av_log(avccontext, AV_LOG_ERROR, |
| 125 "Dirac chroma format %d not supported currently\n", | 122 "Dirac chroma format %d not supported currently\n", |
| 126 src_params->chroma); | 123 src_params->chroma); |
| 127 return -1; | 124 return -1; |
| 128 } | 125 } |
| 129 | 126 |
| 130 avccontext->time_base.den = src_params->frame_rate.numerator; | 127 avccontext->time_base.den = src_params->frame_rate.numerator; |
| 131 avccontext->time_base.num = src_params->frame_rate.denominator; | 128 avccontext->time_base.num = src_params->frame_rate.denominator; |
| 138 avccontext->width, | 135 avccontext->width, |
| 139 avccontext->height); | 136 avccontext->height); |
| 140 | 137 |
| 141 /* allocate output buffer */ | 138 /* allocate output buffer */ |
| 142 if (!p_dirac_params->p_out_frame_buf) | 139 if (!p_dirac_params->p_out_frame_buf) |
| 143 p_dirac_params->p_out_frame_buf = av_malloc (pict_size); | 140 p_dirac_params->p_out_frame_buf = av_malloc(pict_size); |
| 144 buffer[0] = p_dirac_params->p_out_frame_buf; | 141 buffer[0] = p_dirac_params->p_out_frame_buf; |
| 145 buffer[1] = p_dirac_params->p_out_frame_buf + | 142 buffer[1] = p_dirac_params->p_out_frame_buf + |
| 146 pic.linesize[0] * avccontext->height; | 143 pic.linesize[0] * avccontext->height; |
| 147 buffer[2] = buffer[1] + | 144 buffer[2] = buffer[1] + |
| 148 pic.linesize[1] * src_params->chroma_height; | 145 pic.linesize[1] * src_params->chroma_height; |
| 175 | 172 |
| 176 | 173 |
| 177 static av_cold int libdirac_decode_close(AVCodecContext *avccontext) | 174 static av_cold int libdirac_decode_close(AVCodecContext *avccontext) |
| 178 { | 175 { |
| 179 FfmpegDiracDecoderParams *p_dirac_params = avccontext->priv_data; | 176 FfmpegDiracDecoderParams *p_dirac_params = avccontext->priv_data; |
| 180 dirac_decoder_close (p_dirac_params->p_decoder); | 177 dirac_decoder_close(p_dirac_params->p_decoder); |
| 181 | 178 |
| 182 av_freep(&p_dirac_params->p_out_frame_buf); | 179 av_freep(&p_dirac_params->p_out_frame_buf); |
| 183 | 180 |
| 184 return 0 ; | 181 return 0; |
| 185 } | 182 } |
| 186 | 183 |
| 187 static void libdirac_flush (AVCodecContext *avccontext) | 184 static void libdirac_flush(AVCodecContext *avccontext) |
| 188 { | 185 { |
| 189 /* Got a seek request. We will need free memory held in the private | 186 /* Got a seek request. We will need free memory held in the private |
| 190 * context and free the current Dirac decoder handle and then open | 187 * context and free the current Dirac decoder handle and then open |
| 191 * a new decoder handle. */ | 188 * a new decoder handle. */ |
| 192 libdirac_decode_close (avccontext); | 189 libdirac_decode_close(avccontext); |
| 193 libdirac_decode_init (avccontext); | 190 libdirac_decode_init(avccontext); |
| 194 return; | 191 return; |
| 195 } | 192 } |
| 196 | 193 |
| 197 | 194 |
| 198 | 195 |
| 206 libdirac_decode_close, | 203 libdirac_decode_close, |
| 207 libdirac_decode_frame, | 204 libdirac_decode_frame, |
| 208 CODEC_CAP_DELAY, | 205 CODEC_CAP_DELAY, |
| 209 .flush = libdirac_flush, | 206 .flush = libdirac_flush, |
| 210 .long_name = NULL_IF_CONFIG_SMALL("libdirac Dirac 2.2"), | 207 .long_name = NULL_IF_CONFIG_SMALL("libdirac Dirac 2.2"), |
| 211 } ; | 208 }; |
