Mercurial > libavcodec.hg
annotate libdiracdec.c @ 11621:84df190892f4 libavcodec
Fix grammar: a expression -> an expression.
| author | stefano |
|---|---|
| date | Mon, 12 Apr 2010 21:49:04 +0000 |
| parents | 8a4984c5cacc |
| children | 7dd2a45249a9 |
| rev | line source |
|---|---|
| 6734 | 1 /* |
| 2 * Dirac decoder support via libdirac library | |
| 3 * Copyright (c) 2005 BBC, Andrew Kennedy <dirac at rd dot bbc dot co dot uk> | |
| 4 * Copyright (c) 2006-2008 BBC, Anuradha Suraparaju <asuraparaju at gmail dot com > | |
| 5 * | |
| 6 * This file is part of FFmpeg. | |
| 7 * | |
| 8 * FFmpeg is free software; you can redistribute it and/or | |
| 9 * modify it under the terms of the GNU Lesser General Public | |
| 10 * License as published by the Free Software Foundation; either | |
| 11 * version 2.1 of the License, or (at your option) any later version. | |
| 12 * | |
| 13 * FFmpeg 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 GNU | |
| 16 * Lesser General Public License for more details. | |
| 17 * | |
| 18 * You should have received a copy of the GNU Lesser General Public | |
| 19 * License along with FFmpeg; if not, write to the Free Software | |
| 20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | |
| 21 */ | |
| 22 | |
| 23 /** | |
|
8718
e9d9d946f213
Use full internal pathname in doxygen @file directives.
diego
parents:
8422
diff
changeset
|
24 * @file libavcodec/libdiracdec.c |
| 6734 | 25 * Dirac decoder support via libdirac library; more details about the Dirac |
| 26 * project can be found at http://dirac.sourceforge.net/. | |
| 27 * The libdirac_decoder library implements Dirac specification version 2.2 | |
| 28 * (http://dirac.sourceforge.net/specification.html). | |
| 29 */ | |
| 30 | |
| 31 #include "libdirac.h" | |
| 32 | |
| 33 #undef NDEBUG | |
| 34 #include <assert.h> | |
| 35 | |
| 36 #include <libdirac_decoder/dirac_parser.h> | |
| 37 | |
| 38 /** contains a single frame returned from Dirac */ | |
|
10060
965220ebc611
cosmetics: indentation, prettyprinting, K&R coding style
diego
parents:
10056
diff
changeset
|
39 typedef struct FfmpegDiracDecoderParams { |
| 6734 | 40 /** decoder handle */ |
| 41 dirac_decoder_t* p_decoder; | |
| 42 | |
| 43 /** buffer to hold decoded frame */ | |
| 44 unsigned char* p_out_frame_buf; | |
| 45 } FfmpegDiracDecoderParams; | |
| 46 | |
| 47 | |
| 48 /** | |
| 49 * returns FFmpeg chroma format | |
| 50 */ | |
| 51 static enum PixelFormat GetFfmpegChromaFormat(dirac_chroma_t dirac_pix_fmt) | |
| 52 { | |
| 53 int num_formats = sizeof(ffmpeg_dirac_pixel_format_map) / | |
| 54 sizeof(ffmpeg_dirac_pixel_format_map[0]); | |
| 55 int idx; | |
| 56 | |
|
10056
646065f63290
Remove useless braces around if/for/while expressions.
diego
parents:
10055
diff
changeset
|
57 for (idx = 0; idx < num_formats; ++idx) |
|
646065f63290
Remove useless braces around if/for/while expressions.
diego
parents:
10055
diff
changeset
|
58 if (ffmpeg_dirac_pixel_format_map[idx].dirac_pix_fmt == dirac_pix_fmt) |
| 6734 | 59 return ffmpeg_dirac_pixel_format_map[idx].ff_pix_fmt; |
| 60 return PIX_FMT_NONE; | |
| 61 } | |
| 62 | |
|
9007
043574c5c153
Add missing av_cold in static init/close functions.
stefano
parents:
8718
diff
changeset
|
63 static av_cold int libdirac_decode_init(AVCodecContext *avccontext) |
| 6734 | 64 { |
| 65 | |
|
10060
965220ebc611
cosmetics: indentation, prettyprinting, K&R coding style
diego
parents:
10056
diff
changeset
|
66 FfmpegDiracDecoderParams *p_dirac_params = avccontext->priv_data; |
| 6734 | 67 p_dirac_params->p_decoder = dirac_decoder_init(avccontext->debug); |
| 68 | |
| 69 if (!p_dirac_params->p_decoder) | |
| 70 return -1; | |
| 71 | |
|
10060
965220ebc611
cosmetics: indentation, prettyprinting, K&R coding style
diego
parents:
10056
diff
changeset
|
72 return 0; |
| 6734 | 73 } |
| 74 | |
| 75 static int libdirac_decode_frame(AVCodecContext *avccontext, | |
| 76 void *data, int *data_size, | |
|
9355
54bc8a2727b0
Implement avcodec_decode_video2(), _audio3() and _subtitle2() which takes an
rbultje
parents:
9007
diff
changeset
|
77 AVPacket *avpkt) |
| 6734 | 78 { |
|
9355
54bc8a2727b0
Implement avcodec_decode_video2(), _audio3() and _subtitle2() which takes an
rbultje
parents:
9007
diff
changeset
|
79 const uint8_t *buf = avpkt->data; |
|
54bc8a2727b0
Implement avcodec_decode_video2(), _audio3() and _subtitle2() which takes an
rbultje
parents:
9007
diff
changeset
|
80 int buf_size = avpkt->size; |
| 6734 | 81 |
| 82 FfmpegDiracDecoderParams *p_dirac_params = avccontext->priv_data; | |
| 83 AVPicture *picture = data; | |
| 84 AVPicture pic; | |
| 85 int pict_size; | |
| 86 unsigned char *buffer[3]; | |
| 87 | |
| 88 *data_size = 0; | |
| 89 | |
|
10060
965220ebc611
cosmetics: indentation, prettyprinting, K&R coding style
diego
parents:
10056
diff
changeset
|
90 if (buf_size > 0) { |
| 6734 | 91 /* set data to decode into buffer */ |
|
10060
965220ebc611
cosmetics: indentation, prettyprinting, K&R coding style
diego
parents:
10056
diff
changeset
|
92 dirac_buffer(p_dirac_params->p_decoder, buf, buf + buf_size); |
|
965220ebc611
cosmetics: indentation, prettyprinting, K&R coding style
diego
parents:
10056
diff
changeset
|
93 if ((buf[4] & 0x08) == 0x08 && (buf[4] & 0x03)) |
|
8422
e623323d409f
Fix incorrectly constructed Dirac parse units that caused A/V sync loss.
diego
parents:
7040
diff
changeset
|
94 avccontext->has_b_frames = 1; |
|
e623323d409f
Fix incorrectly constructed Dirac parse units that caused A/V sync loss.
diego
parents:
7040
diff
changeset
|
95 } |
| 6734 | 96 while (1) { |
| 97 /* parse data and process result */ | |
|
10060
965220ebc611
cosmetics: indentation, prettyprinting, K&R coding style
diego
parents:
10056
diff
changeset
|
98 DecoderState state = dirac_parse(p_dirac_params->p_decoder); |
|
965220ebc611
cosmetics: indentation, prettyprinting, K&R coding style
diego
parents:
10056
diff
changeset
|
99 switch (state) { |
| 6734 | 100 case STATE_BUFFER: |
| 101 return buf_size; | |
| 102 | |
| 103 case STATE_SEQUENCE: | |
| 104 { | |
| 105 /* tell FFmpeg about sequence details */ | |
|
10060
965220ebc611
cosmetics: indentation, prettyprinting, K&R coding style
diego
parents:
10056
diff
changeset
|
106 dirac_sourceparams_t *src_params = &p_dirac_params->p_decoder->src_params; |
| 6734 | 107 |
| 108 if (avcodec_check_dimensions(avccontext, src_params->width, | |
| 109 src_params->height) < 0) { | |
| 110 av_log(avccontext, AV_LOG_ERROR, "Invalid dimensions (%dx%d)\n", | |
| 111 src_params->width, src_params->height); | |
| 112 avccontext->height = avccontext->width = 0; | |
| 113 return -1; | |
| 114 } | |
| 115 | |
| 116 avccontext->height = src_params->height; | |
| 117 avccontext->width = src_params->width; | |
| 118 | |
| 119 avccontext->pix_fmt = GetFfmpegChromaFormat(src_params->chroma); | |
| 120 if (avccontext->pix_fmt == PIX_FMT_NONE) { | |
|
10060
965220ebc611
cosmetics: indentation, prettyprinting, K&R coding style
diego
parents:
10056
diff
changeset
|
121 av_log(avccontext, AV_LOG_ERROR, |
|
965220ebc611
cosmetics: indentation, prettyprinting, K&R coding style
diego
parents:
10056
diff
changeset
|
122 "Dirac chroma format %d not supported currently\n", |
|
965220ebc611
cosmetics: indentation, prettyprinting, K&R coding style
diego
parents:
10056
diff
changeset
|
123 src_params->chroma); |
| 6734 | 124 return -1; |
| 125 } | |
| 126 | |
| 127 avccontext->time_base.den = src_params->frame_rate.numerator; | |
| 128 avccontext->time_base.num = src_params->frame_rate.denominator; | |
| 129 | |
| 130 /* calculate output dimensions */ | |
| 131 avpicture_fill(&pic, NULL, avccontext->pix_fmt, | |
| 132 avccontext->width, avccontext->height); | |
| 133 | |
| 134 pict_size = avpicture_get_size(avccontext->pix_fmt, | |
| 135 avccontext->width, | |
| 136 avccontext->height); | |
| 137 | |
| 138 /* allocate output buffer */ | |
| 10055 | 139 if (!p_dirac_params->p_out_frame_buf) |
|
10060
965220ebc611
cosmetics: indentation, prettyprinting, K&R coding style
diego
parents:
10056
diff
changeset
|
140 p_dirac_params->p_out_frame_buf = av_malloc(pict_size); |
| 6734 | 141 buffer[0] = p_dirac_params->p_out_frame_buf; |
| 142 buffer[1] = p_dirac_params->p_out_frame_buf + | |
| 143 pic.linesize[0] * avccontext->height; | |
| 144 buffer[2] = buffer[1] + | |
| 145 pic.linesize[1] * src_params->chroma_height; | |
| 146 | |
| 147 /* tell Dirac about output destination */ | |
| 148 dirac_set_buf(p_dirac_params->p_decoder, buffer, NULL); | |
| 149 break; | |
| 150 } | |
| 151 case STATE_SEQUENCE_END: | |
| 152 break; | |
| 153 | |
| 154 case STATE_PICTURE_AVAIL: | |
| 155 /* fill picture with current buffer data from Dirac */ | |
| 156 avpicture_fill(picture, p_dirac_params->p_out_frame_buf, | |
| 157 avccontext->pix_fmt, | |
| 158 avccontext->width, avccontext->height); | |
| 159 *data_size = sizeof(AVPicture); | |
| 160 return buf_size; | |
| 161 | |
| 162 case STATE_INVALID: | |
| 163 return -1; | |
| 164 | |
| 165 default: | |
| 166 break; | |
| 167 } | |
| 168 } | |
| 169 | |
| 170 return buf_size; | |
| 171 } | |
| 172 | |
| 173 | |
|
9007
043574c5c153
Add missing av_cold in static init/close functions.
stefano
parents:
8718
diff
changeset
|
174 static av_cold int libdirac_decode_close(AVCodecContext *avccontext) |
| 6734 | 175 { |
| 176 FfmpegDiracDecoderParams *p_dirac_params = avccontext->priv_data; | |
|
10060
965220ebc611
cosmetics: indentation, prettyprinting, K&R coding style
diego
parents:
10056
diff
changeset
|
177 dirac_decoder_close(p_dirac_params->p_decoder); |
| 6734 | 178 |
| 179 av_freep(&p_dirac_params->p_out_frame_buf); | |
| 180 | |
|
10060
965220ebc611
cosmetics: indentation, prettyprinting, K&R coding style
diego
parents:
10056
diff
changeset
|
181 return 0; |
| 6734 | 182 } |
| 183 | |
|
10060
965220ebc611
cosmetics: indentation, prettyprinting, K&R coding style
diego
parents:
10056
diff
changeset
|
184 static void libdirac_flush(AVCodecContext *avccontext) |
| 6734 | 185 { |
| 186 /* Got a seek request. We will need free memory held in the private | |
| 187 * context and free the current Dirac decoder handle and then open | |
| 188 * a new decoder handle. */ | |
|
10060
965220ebc611
cosmetics: indentation, prettyprinting, K&R coding style
diego
parents:
10056
diff
changeset
|
189 libdirac_decode_close(avccontext); |
|
965220ebc611
cosmetics: indentation, prettyprinting, K&R coding style
diego
parents:
10056
diff
changeset
|
190 libdirac_decode_init(avccontext); |
| 6734 | 191 return; |
| 192 } | |
| 193 | |
| 194 | |
| 195 | |
| 196 AVCodec libdirac_decoder = { | |
| 197 "libdirac", | |
|
11560
8a4984c5cacc
Define AVMediaType enum, and use it instead of enum CodecType, which
stefano
parents:
10060
diff
changeset
|
198 AVMEDIA_TYPE_VIDEO, |
| 6734 | 199 CODEC_ID_DIRAC, |
| 200 sizeof(FfmpegDiracDecoderParams), | |
| 201 libdirac_decode_init, | |
| 202 NULL, | |
| 203 libdirac_decode_close, | |
| 204 libdirac_decode_frame, | |
| 205 CODEC_CAP_DELAY, | |
|
6819
43bede126ef6
missing codec long names by Stefano Sabatini, stefano.sabatini-lala poste it
diego
parents:
6734
diff
changeset
|
206 .flush = libdirac_flush, |
|
7040
e943e1409077
Make AVCodec long_names definition conditional depending on CONFIG_SMALL.
stefano
parents:
6819
diff
changeset
|
207 .long_name = NULL_IF_CONFIG_SMALL("libdirac Dirac 2.2"), |
|
10060
965220ebc611
cosmetics: indentation, prettyprinting, K&R coding style
diego
parents:
10056
diff
changeset
|
208 }; |
