Mercurial > libavcodec.hg
annotate libdiracdec.c @ 12515:307776e26174 libavcodec
Support deinterlacing of YUVJ422P in old deinterlacer.
Patch by Maksym Veremeyenko verem at m1stereo tv.
| author | banan |
|---|---|
| date | Sat, 25 Sep 2010 14:37:54 +0000 |
| parents | ffb3668ff7af |
| children |
| 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 /** | |
|
11644
7dd2a45249a9
Remove explicit filename from Doxygen @file commands.
diego
parents:
11560
diff
changeset
|
24 * @file |
| 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 | |
|
12376
7e9b2d528e59
Fix the compilation of some libavcodec/lib* files which were not
stefano
parents:
12372
diff
changeset
|
31 #include "libavcore/imgutils.h" |
| 6734 | 32 #include "libdirac.h" |
| 33 | |
| 34 #undef NDEBUG | |
| 35 #include <assert.h> | |
| 36 | |
| 37 #include <libdirac_decoder/dirac_parser.h> | |
| 38 | |
| 39 /** contains a single frame returned from Dirac */ | |
|
10060
965220ebc611
cosmetics: indentation, prettyprinting, K&R coding style
diego
parents:
10056
diff
changeset
|
40 typedef struct FfmpegDiracDecoderParams { |
| 6734 | 41 /** decoder handle */ |
| 42 dirac_decoder_t* p_decoder; | |
| 43 | |
| 44 /** buffer to hold decoded frame */ | |
| 45 unsigned char* p_out_frame_buf; | |
| 46 } FfmpegDiracDecoderParams; | |
| 47 | |
| 48 | |
| 49 /** | |
| 50 * returns FFmpeg chroma format | |
| 51 */ | |
| 52 static enum PixelFormat GetFfmpegChromaFormat(dirac_chroma_t dirac_pix_fmt) | |
| 53 { | |
| 54 int num_formats = sizeof(ffmpeg_dirac_pixel_format_map) / | |
| 55 sizeof(ffmpeg_dirac_pixel_format_map[0]); | |
| 56 int idx; | |
| 57 | |
|
10056
646065f63290
Remove useless braces around if/for/while expressions.
diego
parents:
10055
diff
changeset
|
58 for (idx = 0; idx < num_formats; ++idx) |
|
646065f63290
Remove useless braces around if/for/while expressions.
diego
parents:
10055
diff
changeset
|
59 if (ffmpeg_dirac_pixel_format_map[idx].dirac_pix_fmt == dirac_pix_fmt) |
| 6734 | 60 return ffmpeg_dirac_pixel_format_map[idx].ff_pix_fmt; |
| 61 return PIX_FMT_NONE; | |
| 62 } | |
| 63 | |
|
9007
043574c5c153
Add missing av_cold in static init/close functions.
stefano
parents:
8718
diff
changeset
|
64 static av_cold int libdirac_decode_init(AVCodecContext *avccontext) |
| 6734 | 65 { |
| 66 | |
|
10060
965220ebc611
cosmetics: indentation, prettyprinting, K&R coding style
diego
parents:
10056
diff
changeset
|
67 FfmpegDiracDecoderParams *p_dirac_params = avccontext->priv_data; |
| 6734 | 68 p_dirac_params->p_decoder = dirac_decoder_init(avccontext->debug); |
| 69 | |
| 70 if (!p_dirac_params->p_decoder) | |
| 71 return -1; | |
| 72 | |
|
10060
965220ebc611
cosmetics: indentation, prettyprinting, K&R coding style
diego
parents:
10056
diff
changeset
|
73 return 0; |
| 6734 | 74 } |
| 75 | |
| 76 static int libdirac_decode_frame(AVCodecContext *avccontext, | |
| 77 void *data, int *data_size, | |
|
9355
54bc8a2727b0
Implement avcodec_decode_video2(), _audio3() and _subtitle2() which takes an
rbultje
parents:
9007
diff
changeset
|
78 AVPacket *avpkt) |
| 6734 | 79 { |
|
9355
54bc8a2727b0
Implement avcodec_decode_video2(), _audio3() and _subtitle2() which takes an
rbultje
parents:
9007
diff
changeset
|
80 const uint8_t *buf = avpkt->data; |
|
54bc8a2727b0
Implement avcodec_decode_video2(), _audio3() and _subtitle2() which takes an
rbultje
parents:
9007
diff
changeset
|
81 int buf_size = avpkt->size; |
| 6734 | 82 |
| 83 FfmpegDiracDecoderParams *p_dirac_params = avccontext->priv_data; | |
| 84 AVPicture *picture = data; | |
| 85 AVPicture pic; | |
| 86 int pict_size; | |
| 87 unsigned char *buffer[3]; | |
| 88 | |
| 89 *data_size = 0; | |
| 90 | |
|
10060
965220ebc611
cosmetics: indentation, prettyprinting, K&R coding style
diego
parents:
10056
diff
changeset
|
91 if (buf_size > 0) { |
| 6734 | 92 /* set data to decode into buffer */ |
|
10060
965220ebc611
cosmetics: indentation, prettyprinting, K&R coding style
diego
parents:
10056
diff
changeset
|
93 dirac_buffer(p_dirac_params->p_decoder, buf, buf + buf_size); |
|
965220ebc611
cosmetics: indentation, prettyprinting, K&R coding style
diego
parents:
10056
diff
changeset
|
94 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
|
95 avccontext->has_b_frames = 1; |
|
e623323d409f
Fix incorrectly constructed Dirac parse units that caused A/V sync loss.
diego
parents:
7040
diff
changeset
|
96 } |
| 6734 | 97 while (1) { |
| 98 /* parse data and process result */ | |
|
10060
965220ebc611
cosmetics: indentation, prettyprinting, K&R coding style
diego
parents:
10056
diff
changeset
|
99 DecoderState state = dirac_parse(p_dirac_params->p_decoder); |
|
965220ebc611
cosmetics: indentation, prettyprinting, K&R coding style
diego
parents:
10056
diff
changeset
|
100 switch (state) { |
| 6734 | 101 case STATE_BUFFER: |
| 102 return buf_size; | |
| 103 | |
| 104 case STATE_SEQUENCE: | |
| 105 { | |
| 106 /* tell FFmpeg about sequence details */ | |
|
10060
965220ebc611
cosmetics: indentation, prettyprinting, K&R coding style
diego
parents:
10056
diff
changeset
|
107 dirac_sourceparams_t *src_params = &p_dirac_params->p_decoder->src_params; |
| 6734 | 108 |
|
12462
ffb3668ff7af
Use new imgutils.h API names, fix deprecation warnings.
stefano
parents:
12376
diff
changeset
|
109 if (av_image_check_size(src_params->width, src_params->height, |
|
12372
914f484bb476
Remove use of the deprecated function avcodec_check_dimensions(), use
stefano
parents:
11644
diff
changeset
|
110 0, avccontext) < 0) { |
| 6734 | 111 av_log(avccontext, AV_LOG_ERROR, "Invalid dimensions (%dx%d)\n", |
| 112 src_params->width, src_params->height); | |
| 113 avccontext->height = avccontext->width = 0; | |
| 114 return -1; | |
| 115 } | |
| 116 | |
| 117 avccontext->height = src_params->height; | |
| 118 avccontext->width = src_params->width; | |
| 119 | |
| 120 avccontext->pix_fmt = GetFfmpegChromaFormat(src_params->chroma); | |
| 121 if (avccontext->pix_fmt == PIX_FMT_NONE) { | |
|
10060
965220ebc611
cosmetics: indentation, prettyprinting, K&R coding style
diego
parents:
10056
diff
changeset
|
122 av_log(avccontext, AV_LOG_ERROR, |
|
965220ebc611
cosmetics: indentation, prettyprinting, K&R coding style
diego
parents:
10056
diff
changeset
|
123 "Dirac chroma format %d not supported currently\n", |
|
965220ebc611
cosmetics: indentation, prettyprinting, K&R coding style
diego
parents:
10056
diff
changeset
|
124 src_params->chroma); |
| 6734 | 125 return -1; |
| 126 } | |
| 127 | |
| 128 avccontext->time_base.den = src_params->frame_rate.numerator; | |
| 129 avccontext->time_base.num = src_params->frame_rate.denominator; | |
| 130 | |
| 131 /* calculate output dimensions */ | |
| 132 avpicture_fill(&pic, NULL, avccontext->pix_fmt, | |
| 133 avccontext->width, avccontext->height); | |
| 134 | |
| 135 pict_size = avpicture_get_size(avccontext->pix_fmt, | |
| 136 avccontext->width, | |
| 137 avccontext->height); | |
| 138 | |
| 139 /* allocate output buffer */ | |
| 10055 | 140 if (!p_dirac_params->p_out_frame_buf) |
|
10060
965220ebc611
cosmetics: indentation, prettyprinting, K&R coding style
diego
parents:
10056
diff
changeset
|
141 p_dirac_params->p_out_frame_buf = av_malloc(pict_size); |
| 6734 | 142 buffer[0] = p_dirac_params->p_out_frame_buf; |
| 143 buffer[1] = p_dirac_params->p_out_frame_buf + | |
| 144 pic.linesize[0] * avccontext->height; | |
| 145 buffer[2] = buffer[1] + | |
| 146 pic.linesize[1] * src_params->chroma_height; | |
| 147 | |
| 148 /* tell Dirac about output destination */ | |
| 149 dirac_set_buf(p_dirac_params->p_decoder, buffer, NULL); | |
| 150 break; | |
| 151 } | |
| 152 case STATE_SEQUENCE_END: | |
| 153 break; | |
| 154 | |
| 155 case STATE_PICTURE_AVAIL: | |
| 156 /* fill picture with current buffer data from Dirac */ | |
| 157 avpicture_fill(picture, p_dirac_params->p_out_frame_buf, | |
| 158 avccontext->pix_fmt, | |
| 159 avccontext->width, avccontext->height); | |
| 160 *data_size = sizeof(AVPicture); | |
| 161 return buf_size; | |
| 162 | |
| 163 case STATE_INVALID: | |
| 164 return -1; | |
| 165 | |
| 166 default: | |
| 167 break; | |
| 168 } | |
| 169 } | |
| 170 | |
| 171 return buf_size; | |
| 172 } | |
| 173 | |
| 174 | |
|
9007
043574c5c153
Add missing av_cold in static init/close functions.
stefano
parents:
8718
diff
changeset
|
175 static av_cold int libdirac_decode_close(AVCodecContext *avccontext) |
| 6734 | 176 { |
| 177 FfmpegDiracDecoderParams *p_dirac_params = avccontext->priv_data; | |
|
10060
965220ebc611
cosmetics: indentation, prettyprinting, K&R coding style
diego
parents:
10056
diff
changeset
|
178 dirac_decoder_close(p_dirac_params->p_decoder); |
| 6734 | 179 |
| 180 av_freep(&p_dirac_params->p_out_frame_buf); | |
| 181 | |
|
10060
965220ebc611
cosmetics: indentation, prettyprinting, K&R coding style
diego
parents:
10056
diff
changeset
|
182 return 0; |
| 6734 | 183 } |
| 184 | |
|
10060
965220ebc611
cosmetics: indentation, prettyprinting, K&R coding style
diego
parents:
10056
diff
changeset
|
185 static void libdirac_flush(AVCodecContext *avccontext) |
| 6734 | 186 { |
| 187 /* Got a seek request. We will need free memory held in the private | |
| 188 * context and free the current Dirac decoder handle and then open | |
| 189 * a new decoder handle. */ | |
|
10060
965220ebc611
cosmetics: indentation, prettyprinting, K&R coding style
diego
parents:
10056
diff
changeset
|
190 libdirac_decode_close(avccontext); |
|
965220ebc611
cosmetics: indentation, prettyprinting, K&R coding style
diego
parents:
10056
diff
changeset
|
191 libdirac_decode_init(avccontext); |
| 6734 | 192 return; |
| 193 } | |
| 194 | |
| 195 | |
| 196 | |
| 197 AVCodec libdirac_decoder = { | |
| 198 "libdirac", | |
|
11560
8a4984c5cacc
Define AVMediaType enum, and use it instead of enum CodecType, which
stefano
parents:
10060
diff
changeset
|
199 AVMEDIA_TYPE_VIDEO, |
| 6734 | 200 CODEC_ID_DIRAC, |
| 201 sizeof(FfmpegDiracDecoderParams), | |
| 202 libdirac_decode_init, | |
| 203 NULL, | |
| 204 libdirac_decode_close, | |
| 205 libdirac_decode_frame, | |
| 206 CODEC_CAP_DELAY, | |
|
6819
43bede126ef6
missing codec long names by Stefano Sabatini, stefano.sabatini-lala poste it
diego
parents:
6734
diff
changeset
|
207 .flush = libdirac_flush, |
|
7040
e943e1409077
Make AVCodec long_names definition conditional depending on CONFIG_SMALL.
stefano
parents:
6819
diff
changeset
|
208 .long_name = NULL_IF_CONFIG_SMALL("libdirac Dirac 2.2"), |
|
10060
965220ebc611
cosmetics: indentation, prettyprinting, K&R coding style
diego
parents:
10056
diff
changeset
|
209 }; |
