annotate libschroedinger.c @ 11280:fea25a6f874e libavcodec

3rd and hopefully last 100l fix.
author michael
date Wed, 24 Feb 2010 22:13:20 +0000
parents 09f2db2d7c90
children 7dd2a45249a9
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
6738
bdacae101076 Add Dirac support through libschroedinger.
diego
parents:
diff changeset
1 /*
bdacae101076 Add Dirac support through libschroedinger.
diego
parents:
diff changeset
2 * Copyright (c) 2008 BBC, Anuradha Suraparaju <asuraparaju at gmail dot com >
bdacae101076 Add Dirac support through libschroedinger.
diego
parents:
diff changeset
3 *
bdacae101076 Add Dirac support through libschroedinger.
diego
parents:
diff changeset
4 * This file is part of FFmpeg.
bdacae101076 Add Dirac support through libschroedinger.
diego
parents:
diff changeset
5 *
bdacae101076 Add Dirac support through libschroedinger.
diego
parents:
diff changeset
6 * FFmpeg is free software; you can redistribute it and/or
bdacae101076 Add Dirac support through libschroedinger.
diego
parents:
diff changeset
7 * modify it under the terms of the GNU Lesser General Public
bdacae101076 Add Dirac support through libschroedinger.
diego
parents:
diff changeset
8 * License as published by the Free Software Foundation; either
bdacae101076 Add Dirac support through libschroedinger.
diego
parents:
diff changeset
9 * version 2.1 of the License, or (at your option) any later version.
bdacae101076 Add Dirac support through libschroedinger.
diego
parents:
diff changeset
10 *
bdacae101076 Add Dirac support through libschroedinger.
diego
parents:
diff changeset
11 * FFmpeg is distributed in the hope that it will be useful,
bdacae101076 Add Dirac support through libschroedinger.
diego
parents:
diff changeset
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
bdacae101076 Add Dirac support through libschroedinger.
diego
parents:
diff changeset
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
bdacae101076 Add Dirac support through libschroedinger.
diego
parents:
diff changeset
14 * Lesser General Public License for more details.
bdacae101076 Add Dirac support through libschroedinger.
diego
parents:
diff changeset
15 *
bdacae101076 Add Dirac support through libschroedinger.
diego
parents:
diff changeset
16 * You should have received a copy of the GNU Lesser General Public
bdacae101076 Add Dirac support through libschroedinger.
diego
parents:
diff changeset
17 * License along with FFmpeg; if not, write to the Free Software
bdacae101076 Add Dirac support through libschroedinger.
diego
parents:
diff changeset
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
bdacae101076 Add Dirac support through libschroedinger.
diego
parents:
diff changeset
19 */
bdacae101076 Add Dirac support through libschroedinger.
diego
parents:
diff changeset
20
bdacae101076 Add Dirac support through libschroedinger.
diego
parents:
diff changeset
21 /**
8718
e9d9d946f213 Use full internal pathname in doxygen @file directives.
diego
parents: 6738
diff changeset
22 * @file libavcodec/libschroedinger.c
6738
bdacae101076 Add Dirac support through libschroedinger.
diego
parents:
diff changeset
23 * function definitions common to libschroedingerdec.c and libschroedingerenc.c
bdacae101076 Add Dirac support through libschroedinger.
diego
parents:
diff changeset
24 */
bdacae101076 Add Dirac support through libschroedinger.
diego
parents:
diff changeset
25
bdacae101076 Add Dirac support through libschroedinger.
diego
parents:
diff changeset
26 #include "libdirac_libschro.h"
bdacae101076 Add Dirac support through libschroedinger.
diego
parents:
diff changeset
27 #include "libschroedinger.h"
bdacae101076 Add Dirac support through libschroedinger.
diego
parents:
diff changeset
28
bdacae101076 Add Dirac support through libschroedinger.
diego
parents:
diff changeset
29 /**
bdacae101076 Add Dirac support through libschroedinger.
diego
parents:
diff changeset
30 * Schroedinger video preset table. Ensure that this tables matches up correctly
bdacae101076 Add Dirac support through libschroedinger.
diego
parents:
diff changeset
31 * with the ff_dirac_schro_video_format_info table in libdirac_libschro.c.
bdacae101076 Add Dirac support through libschroedinger.
diego
parents:
diff changeset
32 */
bdacae101076 Add Dirac support through libschroedinger.
diego
parents:
diff changeset
33 static const SchroVideoFormatEnum ff_schro_video_formats[]={
bdacae101076 Add Dirac support through libschroedinger.
diego
parents:
diff changeset
34 SCHRO_VIDEO_FORMAT_CUSTOM ,
bdacae101076 Add Dirac support through libschroedinger.
diego
parents:
diff changeset
35 SCHRO_VIDEO_FORMAT_QSIF ,
bdacae101076 Add Dirac support through libschroedinger.
diego
parents:
diff changeset
36 SCHRO_VIDEO_FORMAT_QCIF ,
bdacae101076 Add Dirac support through libschroedinger.
diego
parents:
diff changeset
37 SCHRO_VIDEO_FORMAT_SIF ,
bdacae101076 Add Dirac support through libschroedinger.
diego
parents:
diff changeset
38 SCHRO_VIDEO_FORMAT_CIF ,
bdacae101076 Add Dirac support through libschroedinger.
diego
parents:
diff changeset
39 SCHRO_VIDEO_FORMAT_4SIF ,
bdacae101076 Add Dirac support through libschroedinger.
diego
parents:
diff changeset
40 SCHRO_VIDEO_FORMAT_4CIF ,
bdacae101076 Add Dirac support through libschroedinger.
diego
parents:
diff changeset
41 SCHRO_VIDEO_FORMAT_SD480I_60 ,
bdacae101076 Add Dirac support through libschroedinger.
diego
parents:
diff changeset
42 SCHRO_VIDEO_FORMAT_SD576I_50 ,
bdacae101076 Add Dirac support through libschroedinger.
diego
parents:
diff changeset
43 SCHRO_VIDEO_FORMAT_HD720P_60 ,
bdacae101076 Add Dirac support through libschroedinger.
diego
parents:
diff changeset
44 SCHRO_VIDEO_FORMAT_HD720P_50 ,
bdacae101076 Add Dirac support through libschroedinger.
diego
parents:
diff changeset
45 SCHRO_VIDEO_FORMAT_HD1080I_60 ,
bdacae101076 Add Dirac support through libschroedinger.
diego
parents:
diff changeset
46 SCHRO_VIDEO_FORMAT_HD1080I_50 ,
bdacae101076 Add Dirac support through libschroedinger.
diego
parents:
diff changeset
47 SCHRO_VIDEO_FORMAT_HD1080P_60 ,
bdacae101076 Add Dirac support through libschroedinger.
diego
parents:
diff changeset
48 SCHRO_VIDEO_FORMAT_HD1080P_50 ,
bdacae101076 Add Dirac support through libschroedinger.
diego
parents:
diff changeset
49 SCHRO_VIDEO_FORMAT_DC2K_24 ,
bdacae101076 Add Dirac support through libschroedinger.
diego
parents:
diff changeset
50 SCHRO_VIDEO_FORMAT_DC4K_24 ,
bdacae101076 Add Dirac support through libschroedinger.
diego
parents:
diff changeset
51 };
bdacae101076 Add Dirac support through libschroedinger.
diego
parents:
diff changeset
52
bdacae101076 Add Dirac support through libschroedinger.
diego
parents:
diff changeset
53 SchroVideoFormatEnum ff_get_schro_video_format_preset(AVCodecContext *avccontext)
bdacae101076 Add Dirac support through libschroedinger.
diego
parents:
diff changeset
54 {
bdacae101076 Add Dirac support through libschroedinger.
diego
parents:
diff changeset
55 unsigned int num_formats = sizeof(ff_schro_video_formats) /
bdacae101076 Add Dirac support through libschroedinger.
diego
parents:
diff changeset
56 sizeof(ff_schro_video_formats[0]);
bdacae101076 Add Dirac support through libschroedinger.
diego
parents:
diff changeset
57
bdacae101076 Add Dirac support through libschroedinger.
diego
parents:
diff changeset
58 unsigned int idx = ff_dirac_schro_get_video_format_idx (avccontext);
bdacae101076 Add Dirac support through libschroedinger.
diego
parents:
diff changeset
59
10060
965220ebc611 cosmetics: indentation, prettyprinting, K&R coding style
diego
parents: 8718
diff changeset
60 return (idx < num_formats) ? ff_schro_video_formats[idx] :
965220ebc611 cosmetics: indentation, prettyprinting, K&R coding style
diego
parents: 8718
diff changeset
61 SCHRO_VIDEO_FORMAT_CUSTOM;
6738
bdacae101076 Add Dirac support through libschroedinger.
diego
parents:
diff changeset
62 }
bdacae101076 Add Dirac support through libschroedinger.
diego
parents:
diff changeset
63
bdacae101076 Add Dirac support through libschroedinger.
diego
parents:
diff changeset
64 int ff_get_schro_frame_format (SchroChromaFormat schro_pix_fmt,
bdacae101076 Add Dirac support through libschroedinger.
diego
parents:
diff changeset
65 SchroFrameFormat *schro_frame_fmt)
bdacae101076 Add Dirac support through libschroedinger.
diego
parents:
diff changeset
66 {
bdacae101076 Add Dirac support through libschroedinger.
diego
parents:
diff changeset
67 unsigned int num_formats = sizeof(ffmpeg_schro_pixel_format_map) /
bdacae101076 Add Dirac support through libschroedinger.
diego
parents:
diff changeset
68 sizeof(ffmpeg_schro_pixel_format_map[0]);
bdacae101076 Add Dirac support through libschroedinger.
diego
parents:
diff changeset
69
bdacae101076 Add Dirac support through libschroedinger.
diego
parents:
diff changeset
70 int idx;
bdacae101076 Add Dirac support through libschroedinger.
diego
parents:
diff changeset
71
bdacae101076 Add Dirac support through libschroedinger.
diego
parents:
diff changeset
72 for (idx = 0; idx < num_formats; ++idx) {
bdacae101076 Add Dirac support through libschroedinger.
diego
parents:
diff changeset
73 if (ffmpeg_schro_pixel_format_map[idx].schro_pix_fmt == schro_pix_fmt) {
10060
965220ebc611 cosmetics: indentation, prettyprinting, K&R coding style
diego
parents: 8718
diff changeset
74 *schro_frame_fmt = ffmpeg_schro_pixel_format_map[idx].schro_frame_fmt;
6738
bdacae101076 Add Dirac support through libschroedinger.
diego
parents:
diff changeset
75 return 0;
bdacae101076 Add Dirac support through libschroedinger.
diego
parents:
diff changeset
76 }
bdacae101076 Add Dirac support through libschroedinger.
diego
parents:
diff changeset
77 }
bdacae101076 Add Dirac support through libschroedinger.
diego
parents:
diff changeset
78 return -1;
bdacae101076 Add Dirac support through libschroedinger.
diego
parents:
diff changeset
79 }
10061
09f2db2d7c90 Fix bug caused by difference in stride and picture width.
diego
parents: 10060
diff changeset
80
09f2db2d7c90 Fix bug caused by difference in stride and picture width.
diego
parents: 10060
diff changeset
81 static void FreeSchroFrame(SchroFrame *frame, void *priv)
09f2db2d7c90 Fix bug caused by difference in stride and picture width.
diego
parents: 10060
diff changeset
82 {
09f2db2d7c90 Fix bug caused by difference in stride and picture width.
diego
parents: 10060
diff changeset
83 AVPicture *p_pic = priv;
09f2db2d7c90 Fix bug caused by difference in stride and picture width.
diego
parents: 10060
diff changeset
84
09f2db2d7c90 Fix bug caused by difference in stride and picture width.
diego
parents: 10060
diff changeset
85 if (!p_pic)
09f2db2d7c90 Fix bug caused by difference in stride and picture width.
diego
parents: 10060
diff changeset
86 return;
09f2db2d7c90 Fix bug caused by difference in stride and picture width.
diego
parents: 10060
diff changeset
87
09f2db2d7c90 Fix bug caused by difference in stride and picture width.
diego
parents: 10060
diff changeset
88 avpicture_free(p_pic);
09f2db2d7c90 Fix bug caused by difference in stride and picture width.
diego
parents: 10060
diff changeset
89 av_freep(&p_pic);
09f2db2d7c90 Fix bug caused by difference in stride and picture width.
diego
parents: 10060
diff changeset
90 }
09f2db2d7c90 Fix bug caused by difference in stride and picture width.
diego
parents: 10060
diff changeset
91
09f2db2d7c90 Fix bug caused by difference in stride and picture width.
diego
parents: 10060
diff changeset
92 SchroFrame *ff_create_schro_frame(AVCodecContext *avccontext,
09f2db2d7c90 Fix bug caused by difference in stride and picture width.
diego
parents: 10060
diff changeset
93 SchroFrameFormat schro_frame_fmt)
09f2db2d7c90 Fix bug caused by difference in stride and picture width.
diego
parents: 10060
diff changeset
94 {
09f2db2d7c90 Fix bug caused by difference in stride and picture width.
diego
parents: 10060
diff changeset
95 AVPicture *p_pic;
09f2db2d7c90 Fix bug caused by difference in stride and picture width.
diego
parents: 10060
diff changeset
96 SchroFrame *p_frame;
09f2db2d7c90 Fix bug caused by difference in stride and picture width.
diego
parents: 10060
diff changeset
97 int y_width, uv_width;
09f2db2d7c90 Fix bug caused by difference in stride and picture width.
diego
parents: 10060
diff changeset
98 int y_height, uv_height;
09f2db2d7c90 Fix bug caused by difference in stride and picture width.
diego
parents: 10060
diff changeset
99 int i;
09f2db2d7c90 Fix bug caused by difference in stride and picture width.
diego
parents: 10060
diff changeset
100
09f2db2d7c90 Fix bug caused by difference in stride and picture width.
diego
parents: 10060
diff changeset
101 y_width = avccontext->width;
09f2db2d7c90 Fix bug caused by difference in stride and picture width.
diego
parents: 10060
diff changeset
102 y_height = avccontext->height;
09f2db2d7c90 Fix bug caused by difference in stride and picture width.
diego
parents: 10060
diff changeset
103 uv_width = y_width >> (SCHRO_FRAME_FORMAT_H_SHIFT(schro_frame_fmt));
09f2db2d7c90 Fix bug caused by difference in stride and picture width.
diego
parents: 10060
diff changeset
104 uv_height = y_height >> (SCHRO_FRAME_FORMAT_V_SHIFT(schro_frame_fmt));
09f2db2d7c90 Fix bug caused by difference in stride and picture width.
diego
parents: 10060
diff changeset
105
09f2db2d7c90 Fix bug caused by difference in stride and picture width.
diego
parents: 10060
diff changeset
106 p_pic = av_mallocz(sizeof(AVPicture));
09f2db2d7c90 Fix bug caused by difference in stride and picture width.
diego
parents: 10060
diff changeset
107 avpicture_alloc(p_pic, avccontext->pix_fmt, y_width, y_height);
09f2db2d7c90 Fix bug caused by difference in stride and picture width.
diego
parents: 10060
diff changeset
108
09f2db2d7c90 Fix bug caused by difference in stride and picture width.
diego
parents: 10060
diff changeset
109 p_frame = schro_frame_new();
09f2db2d7c90 Fix bug caused by difference in stride and picture width.
diego
parents: 10060
diff changeset
110 p_frame->format = schro_frame_fmt;
09f2db2d7c90 Fix bug caused by difference in stride and picture width.
diego
parents: 10060
diff changeset
111 p_frame->width = y_width;
09f2db2d7c90 Fix bug caused by difference in stride and picture width.
diego
parents: 10060
diff changeset
112 p_frame->height = y_height;
09f2db2d7c90 Fix bug caused by difference in stride and picture width.
diego
parents: 10060
diff changeset
113 schro_frame_set_free_callback(p_frame, FreeSchroFrame, (void *)p_pic);
09f2db2d7c90 Fix bug caused by difference in stride and picture width.
diego
parents: 10060
diff changeset
114
09f2db2d7c90 Fix bug caused by difference in stride and picture width.
diego
parents: 10060
diff changeset
115 for (i = 0; i < 3; ++i) {
09f2db2d7c90 Fix bug caused by difference in stride and picture width.
diego
parents: 10060
diff changeset
116 p_frame->components[i].width = i ? uv_width : y_width;
09f2db2d7c90 Fix bug caused by difference in stride and picture width.
diego
parents: 10060
diff changeset
117 p_frame->components[i].stride = p_pic->linesize[i];
09f2db2d7c90 Fix bug caused by difference in stride and picture width.
diego
parents: 10060
diff changeset
118 p_frame->components[i].height = i ? uv_height : y_height;
09f2db2d7c90 Fix bug caused by difference in stride and picture width.
diego
parents: 10060
diff changeset
119 p_frame->components[i].length =
09f2db2d7c90 Fix bug caused by difference in stride and picture width.
diego
parents: 10060
diff changeset
120 p_frame->components[i].stride * p_frame->components[i].height;
09f2db2d7c90 Fix bug caused by difference in stride and picture width.
diego
parents: 10060
diff changeset
121 p_frame->components[i].data = p_pic->data[i];
09f2db2d7c90 Fix bug caused by difference in stride and picture width.
diego
parents: 10060
diff changeset
122
09f2db2d7c90 Fix bug caused by difference in stride and picture width.
diego
parents: 10060
diff changeset
123 if (i) {
09f2db2d7c90 Fix bug caused by difference in stride and picture width.
diego
parents: 10060
diff changeset
124 p_frame->components[i].v_shift =
09f2db2d7c90 Fix bug caused by difference in stride and picture width.
diego
parents: 10060
diff changeset
125 SCHRO_FRAME_FORMAT_V_SHIFT(p_frame->format);
09f2db2d7c90 Fix bug caused by difference in stride and picture width.
diego
parents: 10060
diff changeset
126 p_frame->components[i].h_shift =
09f2db2d7c90 Fix bug caused by difference in stride and picture width.
diego
parents: 10060
diff changeset
127 SCHRO_FRAME_FORMAT_H_SHIFT(p_frame->format);
09f2db2d7c90 Fix bug caused by difference in stride and picture width.
diego
parents: 10060
diff changeset
128 }
09f2db2d7c90 Fix bug caused by difference in stride and picture width.
diego
parents: 10060
diff changeset
129 }
09f2db2d7c90 Fix bug caused by difference in stride and picture width.
diego
parents: 10060
diff changeset
130
09f2db2d7c90 Fix bug caused by difference in stride and picture width.
diego
parents: 10060
diff changeset
131 return p_frame;
09f2db2d7c90 Fix bug caused by difference in stride and picture width.
diego
parents: 10060
diff changeset
132 }