annotate raw.c @ 1195:f7522f310c7e libavcodec

segfault fix
author michaelni
date Thu, 17 Apr 2003 19:53:36 +0000
parents c85d33c011ab
children b88dfc4bbf8c
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1139
6842feb093c1 rawvideo patch by (Fred Rothganger <rothgang at uiuc dot edu>)
michaelni
parents:
diff changeset
1 /*
6842feb093c1 rawvideo patch by (Fred Rothganger <rothgang at uiuc dot edu>)
michaelni
parents:
diff changeset
2 * Raw Video Codec
6842feb093c1 rawvideo patch by (Fred Rothganger <rothgang at uiuc dot edu>)
michaelni
parents:
diff changeset
3 * Copyright (c) 2001 Fabrice Bellard.
6842feb093c1 rawvideo patch by (Fred Rothganger <rothgang at uiuc dot edu>)
michaelni
parents:
diff changeset
4 *
6842feb093c1 rawvideo patch by (Fred Rothganger <rothgang at uiuc dot edu>)
michaelni
parents:
diff changeset
5 * This library is free software; you can redistribute it and/or
6842feb093c1 rawvideo patch by (Fred Rothganger <rothgang at uiuc dot edu>)
michaelni
parents:
diff changeset
6 * modify it under the terms of the GNU Lesser General Public
6842feb093c1 rawvideo patch by (Fred Rothganger <rothgang at uiuc dot edu>)
michaelni
parents:
diff changeset
7 * License as published by the Free Software Foundation; either
6842feb093c1 rawvideo patch by (Fred Rothganger <rothgang at uiuc dot edu>)
michaelni
parents:
diff changeset
8 * version 2 of the License, or (at your option) any later version.
6842feb093c1 rawvideo patch by (Fred Rothganger <rothgang at uiuc dot edu>)
michaelni
parents:
diff changeset
9 *
6842feb093c1 rawvideo patch by (Fred Rothganger <rothgang at uiuc dot edu>)
michaelni
parents:
diff changeset
10 * This library is distributed in the hope that it will be useful,
6842feb093c1 rawvideo patch by (Fred Rothganger <rothgang at uiuc dot edu>)
michaelni
parents:
diff changeset
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
6842feb093c1 rawvideo patch by (Fred Rothganger <rothgang at uiuc dot edu>)
michaelni
parents:
diff changeset
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
6842feb093c1 rawvideo patch by (Fred Rothganger <rothgang at uiuc dot edu>)
michaelni
parents:
diff changeset
13 * Lesser General Public License for more details.
6842feb093c1 rawvideo patch by (Fred Rothganger <rothgang at uiuc dot edu>)
michaelni
parents:
diff changeset
14 *
6842feb093c1 rawvideo patch by (Fred Rothganger <rothgang at uiuc dot edu>)
michaelni
parents:
diff changeset
15 * You should have received a copy of the GNU Lesser General Public
6842feb093c1 rawvideo patch by (Fred Rothganger <rothgang at uiuc dot edu>)
michaelni
parents:
diff changeset
16 * License along with this library; if not, write to the Free Software
6842feb093c1 rawvideo patch by (Fred Rothganger <rothgang at uiuc dot edu>)
michaelni
parents:
diff changeset
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
6842feb093c1 rawvideo patch by (Fred Rothganger <rothgang at uiuc dot edu>)
michaelni
parents:
diff changeset
18 */
6842feb093c1 rawvideo patch by (Fred Rothganger <rothgang at uiuc dot edu>)
michaelni
parents:
diff changeset
19
6842feb093c1 rawvideo patch by (Fred Rothganger <rothgang at uiuc dot edu>)
michaelni
parents:
diff changeset
20 /**
6842feb093c1 rawvideo patch by (Fred Rothganger <rothgang at uiuc dot edu>)
michaelni
parents:
diff changeset
21 * @file raw.c
6842feb093c1 rawvideo patch by (Fred Rothganger <rothgang at uiuc dot edu>)
michaelni
parents:
diff changeset
22 * Raw Video Codec
6842feb093c1 rawvideo patch by (Fred Rothganger <rothgang at uiuc dot edu>)
michaelni
parents:
diff changeset
23 */
6842feb093c1 rawvideo patch by (Fred Rothganger <rothgang at uiuc dot edu>)
michaelni
parents:
diff changeset
24
6842feb093c1 rawvideo patch by (Fred Rothganger <rothgang at uiuc dot edu>)
michaelni
parents:
diff changeset
25 #include "avcodec.h"
6842feb093c1 rawvideo patch by (Fred Rothganger <rothgang at uiuc dot edu>)
michaelni
parents:
diff changeset
26
6842feb093c1 rawvideo patch by (Fred Rothganger <rothgang at uiuc dot edu>)
michaelni
parents:
diff changeset
27
6842feb093c1 rawvideo patch by (Fred Rothganger <rothgang at uiuc dot edu>)
michaelni
parents:
diff changeset
28 typedef struct PixleFormatTag {
6842feb093c1 rawvideo patch by (Fred Rothganger <rothgang at uiuc dot edu>)
michaelni
parents:
diff changeset
29 int pix_fmt;
6842feb093c1 rawvideo patch by (Fred Rothganger <rothgang at uiuc dot edu>)
michaelni
parents:
diff changeset
30 unsigned int fourcc;
6842feb093c1 rawvideo patch by (Fred Rothganger <rothgang at uiuc dot edu>)
michaelni
parents:
diff changeset
31 } PixelFormatTag;
6842feb093c1 rawvideo patch by (Fred Rothganger <rothgang at uiuc dot edu>)
michaelni
parents:
diff changeset
32
6842feb093c1 rawvideo patch by (Fred Rothganger <rothgang at uiuc dot edu>)
michaelni
parents:
diff changeset
33 const PixelFormatTag pixelFormatTags[] = {
6842feb093c1 rawvideo patch by (Fred Rothganger <rothgang at uiuc dot edu>)
michaelni
parents:
diff changeset
34 { PIX_FMT_YUV422, MKTAG('Y', '4', '2', '2') },
1155
c85d33c011ab I420 patch by (Sebastien Bechet <s dot bechet at av7 dot net>)
michaelni
parents: 1140
diff changeset
35 { PIX_FMT_YUV420P, MKTAG('I', '4', '2', '0') },
1139
6842feb093c1 rawvideo patch by (Fred Rothganger <rothgang at uiuc dot edu>)
michaelni
parents:
diff changeset
36 { -1, 0 },
6842feb093c1 rawvideo patch by (Fred Rothganger <rothgang at uiuc dot edu>)
michaelni
parents:
diff changeset
37 };
6842feb093c1 rawvideo patch by (Fred Rothganger <rothgang at uiuc dot edu>)
michaelni
parents:
diff changeset
38
6842feb093c1 rawvideo patch by (Fred Rothganger <rothgang at uiuc dot edu>)
michaelni
parents:
diff changeset
39 static int findPixelFormat(unsigned int fourcc)
6842feb093c1 rawvideo patch by (Fred Rothganger <rothgang at uiuc dot edu>)
michaelni
parents:
diff changeset
40 {
6842feb093c1 rawvideo patch by (Fred Rothganger <rothgang at uiuc dot edu>)
michaelni
parents:
diff changeset
41 const PixelFormatTag * tags = pixelFormatTags;
6842feb093c1 rawvideo patch by (Fred Rothganger <rothgang at uiuc dot edu>)
michaelni
parents:
diff changeset
42 while (tags->pix_fmt >= 0) {
6842feb093c1 rawvideo patch by (Fred Rothganger <rothgang at uiuc dot edu>)
michaelni
parents:
diff changeset
43 if (tags->fourcc == fourcc)
6842feb093c1 rawvideo patch by (Fred Rothganger <rothgang at uiuc dot edu>)
michaelni
parents:
diff changeset
44 return tags->pix_fmt;
6842feb093c1 rawvideo patch by (Fred Rothganger <rothgang at uiuc dot edu>)
michaelni
parents:
diff changeset
45 tags++;
6842feb093c1 rawvideo patch by (Fred Rothganger <rothgang at uiuc dot edu>)
michaelni
parents:
diff changeset
46 }
6842feb093c1 rawvideo patch by (Fred Rothganger <rothgang at uiuc dot edu>)
michaelni
parents:
diff changeset
47 return PIX_FMT_YUV420P;
6842feb093c1 rawvideo patch by (Fred Rothganger <rothgang at uiuc dot edu>)
michaelni
parents:
diff changeset
48 }
6842feb093c1 rawvideo patch by (Fred Rothganger <rothgang at uiuc dot edu>)
michaelni
parents:
diff changeset
49
6842feb093c1 rawvideo patch by (Fred Rothganger <rothgang at uiuc dot edu>)
michaelni
parents:
diff changeset
50
6842feb093c1 rawvideo patch by (Fred Rothganger <rothgang at uiuc dot edu>)
michaelni
parents:
diff changeset
51 typedef struct RawVideoContext {
6842feb093c1 rawvideo patch by (Fred Rothganger <rothgang at uiuc dot edu>)
michaelni
parents:
diff changeset
52 unsigned char * buffer; /* block of memory for holding one frame */
6842feb093c1 rawvideo patch by (Fred Rothganger <rothgang at uiuc dot edu>)
michaelni
parents:
diff changeset
53 unsigned char * p; /* current position in buffer */
6842feb093c1 rawvideo patch by (Fred Rothganger <rothgang at uiuc dot edu>)
michaelni
parents:
diff changeset
54 int length; /* number of bytes in buffer */
1195
f7522f310c7e segfault fix
michaelni
parents: 1155
diff changeset
55 AVFrame pic; ///< AVCodecContext.coded_frame
1139
6842feb093c1 rawvideo patch by (Fred Rothganger <rothgang at uiuc dot edu>)
michaelni
parents:
diff changeset
56 } RawVideoContext;
6842feb093c1 rawvideo patch by (Fred Rothganger <rothgang at uiuc dot edu>)
michaelni
parents:
diff changeset
57
6842feb093c1 rawvideo patch by (Fred Rothganger <rothgang at uiuc dot edu>)
michaelni
parents:
diff changeset
58
6842feb093c1 rawvideo patch by (Fred Rothganger <rothgang at uiuc dot edu>)
michaelni
parents:
diff changeset
59 static int raw_init(AVCodecContext *avctx)
6842feb093c1 rawvideo patch by (Fred Rothganger <rothgang at uiuc dot edu>)
michaelni
parents:
diff changeset
60 {
6842feb093c1 rawvideo patch by (Fred Rothganger <rothgang at uiuc dot edu>)
michaelni
parents:
diff changeset
61 RawVideoContext *context = avctx->priv_data;
6842feb093c1 rawvideo patch by (Fred Rothganger <rothgang at uiuc dot edu>)
michaelni
parents:
diff changeset
62
6842feb093c1 rawvideo patch by (Fred Rothganger <rothgang at uiuc dot edu>)
michaelni
parents:
diff changeset
63 if (avctx->codec_tag) {
6842feb093c1 rawvideo patch by (Fred Rothganger <rothgang at uiuc dot edu>)
michaelni
parents:
diff changeset
64 avctx->pix_fmt = findPixelFormat(avctx->codec_tag);
6842feb093c1 rawvideo patch by (Fred Rothganger <rothgang at uiuc dot edu>)
michaelni
parents:
diff changeset
65 }
6842feb093c1 rawvideo patch by (Fred Rothganger <rothgang at uiuc dot edu>)
michaelni
parents:
diff changeset
66
6842feb093c1 rawvideo patch by (Fred Rothganger <rothgang at uiuc dot edu>)
michaelni
parents:
diff changeset
67 context->length = avpicture_get_size(avctx->pix_fmt, avctx->width, avctx->height);
6842feb093c1 rawvideo patch by (Fred Rothganger <rothgang at uiuc dot edu>)
michaelni
parents:
diff changeset
68 context->buffer = av_malloc(context->length);
6842feb093c1 rawvideo patch by (Fred Rothganger <rothgang at uiuc dot edu>)
michaelni
parents:
diff changeset
69 context->p = context->buffer;
6842feb093c1 rawvideo patch by (Fred Rothganger <rothgang at uiuc dot edu>)
michaelni
parents:
diff changeset
70
1195
f7522f310c7e segfault fix
michaelni
parents: 1155
diff changeset
71 context->pic.pict_type= FF_I_TYPE;
f7522f310c7e segfault fix
michaelni
parents: 1155
diff changeset
72 context->pic.key_frame= 1;
f7522f310c7e segfault fix
michaelni
parents: 1155
diff changeset
73 avctx->coded_frame= &context->pic;
f7522f310c7e segfault fix
michaelni
parents: 1155
diff changeset
74
1139
6842feb093c1 rawvideo patch by (Fred Rothganger <rothgang at uiuc dot edu>)
michaelni
parents:
diff changeset
75 if (! context->buffer) {
6842feb093c1 rawvideo patch by (Fred Rothganger <rothgang at uiuc dot edu>)
michaelni
parents:
diff changeset
76 return -1;
6842feb093c1 rawvideo patch by (Fred Rothganger <rothgang at uiuc dot edu>)
michaelni
parents:
diff changeset
77 }
6842feb093c1 rawvideo patch by (Fred Rothganger <rothgang at uiuc dot edu>)
michaelni
parents:
diff changeset
78
6842feb093c1 rawvideo patch by (Fred Rothganger <rothgang at uiuc dot edu>)
michaelni
parents:
diff changeset
79 return 0;
6842feb093c1 rawvideo patch by (Fred Rothganger <rothgang at uiuc dot edu>)
michaelni
parents:
diff changeset
80 }
6842feb093c1 rawvideo patch by (Fred Rothganger <rothgang at uiuc dot edu>)
michaelni
parents:
diff changeset
81
6842feb093c1 rawvideo patch by (Fred Rothganger <rothgang at uiuc dot edu>)
michaelni
parents:
diff changeset
82 static int raw_decode(AVCodecContext *avctx,
6842feb093c1 rawvideo patch by (Fred Rothganger <rothgang at uiuc dot edu>)
michaelni
parents:
diff changeset
83 void *data, int *data_size,
6842feb093c1 rawvideo patch by (Fred Rothganger <rothgang at uiuc dot edu>)
michaelni
parents:
diff changeset
84 uint8_t *buf, int buf_size)
6842feb093c1 rawvideo patch by (Fred Rothganger <rothgang at uiuc dot edu>)
michaelni
parents:
diff changeset
85 {
6842feb093c1 rawvideo patch by (Fred Rothganger <rothgang at uiuc dot edu>)
michaelni
parents:
diff changeset
86 RawVideoContext *context = avctx->priv_data;
1140
michaelni
parents: 1139
diff changeset
87 int bytesNeeded;
1139
6842feb093c1 rawvideo patch by (Fred Rothganger <rothgang at uiuc dot edu>)
michaelni
parents:
diff changeset
88
6842feb093c1 rawvideo patch by (Fred Rothganger <rothgang at uiuc dot edu>)
michaelni
parents:
diff changeset
89 AVPicture * picture = (AVPicture *) data;
6842feb093c1 rawvideo patch by (Fred Rothganger <rothgang at uiuc dot edu>)
michaelni
parents:
diff changeset
90
6842feb093c1 rawvideo patch by (Fred Rothganger <rothgang at uiuc dot edu>)
michaelni
parents:
diff changeset
91 /* Early out without copy if packet size == frame size */
6842feb093c1 rawvideo patch by (Fred Rothganger <rothgang at uiuc dot edu>)
michaelni
parents:
diff changeset
92 if (buf_size == context->length && context->p == context->buffer) {
6842feb093c1 rawvideo patch by (Fred Rothganger <rothgang at uiuc dot edu>)
michaelni
parents:
diff changeset
93 avpicture_fill(picture, buf, avctx->pix_fmt, avctx->width, avctx->height);
6842feb093c1 rawvideo patch by (Fred Rothganger <rothgang at uiuc dot edu>)
michaelni
parents:
diff changeset
94 *data_size = sizeof(AVPicture);
6842feb093c1 rawvideo patch by (Fred Rothganger <rothgang at uiuc dot edu>)
michaelni
parents:
diff changeset
95 return buf_size;
6842feb093c1 rawvideo patch by (Fred Rothganger <rothgang at uiuc dot edu>)
michaelni
parents:
diff changeset
96 }
6842feb093c1 rawvideo patch by (Fred Rothganger <rothgang at uiuc dot edu>)
michaelni
parents:
diff changeset
97
1140
michaelni
parents: 1139
diff changeset
98 bytesNeeded = context->length - (context->p - context->buffer);
1139
6842feb093c1 rawvideo patch by (Fred Rothganger <rothgang at uiuc dot edu>)
michaelni
parents:
diff changeset
99 if (buf_size < bytesNeeded) {
6842feb093c1 rawvideo patch by (Fred Rothganger <rothgang at uiuc dot edu>)
michaelni
parents:
diff changeset
100 memcpy(context->p, buf, buf_size);
6842feb093c1 rawvideo patch by (Fred Rothganger <rothgang at uiuc dot edu>)
michaelni
parents:
diff changeset
101 context->p += buf_size;
6842feb093c1 rawvideo patch by (Fred Rothganger <rothgang at uiuc dot edu>)
michaelni
parents:
diff changeset
102 *data_size = 0;
6842feb093c1 rawvideo patch by (Fred Rothganger <rothgang at uiuc dot edu>)
michaelni
parents:
diff changeset
103 return buf_size;
6842feb093c1 rawvideo patch by (Fred Rothganger <rothgang at uiuc dot edu>)
michaelni
parents:
diff changeset
104 }
6842feb093c1 rawvideo patch by (Fred Rothganger <rothgang at uiuc dot edu>)
michaelni
parents:
diff changeset
105
6842feb093c1 rawvideo patch by (Fred Rothganger <rothgang at uiuc dot edu>)
michaelni
parents:
diff changeset
106 memcpy(context->p, buf, bytesNeeded);
6842feb093c1 rawvideo patch by (Fred Rothganger <rothgang at uiuc dot edu>)
michaelni
parents:
diff changeset
107 context->p = context->buffer;
6842feb093c1 rawvideo patch by (Fred Rothganger <rothgang at uiuc dot edu>)
michaelni
parents:
diff changeset
108 avpicture_fill(picture, context->buffer, avctx->pix_fmt, avctx->width, avctx->height);
6842feb093c1 rawvideo patch by (Fred Rothganger <rothgang at uiuc dot edu>)
michaelni
parents:
diff changeset
109 *data_size = sizeof(AVPicture);
6842feb093c1 rawvideo patch by (Fred Rothganger <rothgang at uiuc dot edu>)
michaelni
parents:
diff changeset
110 return bytesNeeded;
6842feb093c1 rawvideo patch by (Fred Rothganger <rothgang at uiuc dot edu>)
michaelni
parents:
diff changeset
111 }
6842feb093c1 rawvideo patch by (Fred Rothganger <rothgang at uiuc dot edu>)
michaelni
parents:
diff changeset
112
6842feb093c1 rawvideo patch by (Fred Rothganger <rothgang at uiuc dot edu>)
michaelni
parents:
diff changeset
113 static int raw_close(AVCodecContext *avctx)
6842feb093c1 rawvideo patch by (Fred Rothganger <rothgang at uiuc dot edu>)
michaelni
parents:
diff changeset
114 {
6842feb093c1 rawvideo patch by (Fred Rothganger <rothgang at uiuc dot edu>)
michaelni
parents:
diff changeset
115 RawVideoContext *context = avctx->priv_data;
6842feb093c1 rawvideo patch by (Fred Rothganger <rothgang at uiuc dot edu>)
michaelni
parents:
diff changeset
116
6842feb093c1 rawvideo patch by (Fred Rothganger <rothgang at uiuc dot edu>)
michaelni
parents:
diff changeset
117 av_freep(& context->buffer);
6842feb093c1 rawvideo patch by (Fred Rothganger <rothgang at uiuc dot edu>)
michaelni
parents:
diff changeset
118
6842feb093c1 rawvideo patch by (Fred Rothganger <rothgang at uiuc dot edu>)
michaelni
parents:
diff changeset
119 return 0;
6842feb093c1 rawvideo patch by (Fred Rothganger <rothgang at uiuc dot edu>)
michaelni
parents:
diff changeset
120 }
6842feb093c1 rawvideo patch by (Fred Rothganger <rothgang at uiuc dot edu>)
michaelni
parents:
diff changeset
121
6842feb093c1 rawvideo patch by (Fred Rothganger <rothgang at uiuc dot edu>)
michaelni
parents:
diff changeset
122 static int raw_encode(AVCodecContext *avctx,
6842feb093c1 rawvideo patch by (Fred Rothganger <rothgang at uiuc dot edu>)
michaelni
parents:
diff changeset
123 unsigned char *frame, int buf_size, void *data)
6842feb093c1 rawvideo patch by (Fred Rothganger <rothgang at uiuc dot edu>)
michaelni
parents:
diff changeset
124 {
6842feb093c1 rawvideo patch by (Fred Rothganger <rothgang at uiuc dot edu>)
michaelni
parents:
diff changeset
125 AVPicture * picture = data;
6842feb093c1 rawvideo patch by (Fred Rothganger <rothgang at uiuc dot edu>)
michaelni
parents:
diff changeset
126
6842feb093c1 rawvideo patch by (Fred Rothganger <rothgang at uiuc dot edu>)
michaelni
parents:
diff changeset
127 unsigned char *src;
6842feb093c1 rawvideo patch by (Fred Rothganger <rothgang at uiuc dot edu>)
michaelni
parents:
diff changeset
128 unsigned char *dest = frame;
6842feb093c1 rawvideo patch by (Fred Rothganger <rothgang at uiuc dot edu>)
michaelni
parents:
diff changeset
129 int i, j;
6842feb093c1 rawvideo patch by (Fred Rothganger <rothgang at uiuc dot edu>)
michaelni
parents:
diff changeset
130
6842feb093c1 rawvideo patch by (Fred Rothganger <rothgang at uiuc dot edu>)
michaelni
parents:
diff changeset
131 int w = avctx->width;
6842feb093c1 rawvideo patch by (Fred Rothganger <rothgang at uiuc dot edu>)
michaelni
parents:
diff changeset
132 int h = avctx->height;
6842feb093c1 rawvideo patch by (Fred Rothganger <rothgang at uiuc dot edu>)
michaelni
parents:
diff changeset
133 int size = avpicture_get_size(avctx->pix_fmt, w, h);
6842feb093c1 rawvideo patch by (Fred Rothganger <rothgang at uiuc dot edu>)
michaelni
parents:
diff changeset
134
6842feb093c1 rawvideo patch by (Fred Rothganger <rothgang at uiuc dot edu>)
michaelni
parents:
diff changeset
135 if (size > buf_size) {
6842feb093c1 rawvideo patch by (Fred Rothganger <rothgang at uiuc dot edu>)
michaelni
parents:
diff changeset
136 return -1;
6842feb093c1 rawvideo patch by (Fred Rothganger <rothgang at uiuc dot edu>)
michaelni
parents:
diff changeset
137 }
6842feb093c1 rawvideo patch by (Fred Rothganger <rothgang at uiuc dot edu>)
michaelni
parents:
diff changeset
138
6842feb093c1 rawvideo patch by (Fred Rothganger <rothgang at uiuc dot edu>)
michaelni
parents:
diff changeset
139 switch(avctx->pix_fmt) {
6842feb093c1 rawvideo patch by (Fred Rothganger <rothgang at uiuc dot edu>)
michaelni
parents:
diff changeset
140 case PIX_FMT_YUV420P:
6842feb093c1 rawvideo patch by (Fred Rothganger <rothgang at uiuc dot edu>)
michaelni
parents:
diff changeset
141 for(i=0;i<3;i++) {
6842feb093c1 rawvideo patch by (Fred Rothganger <rothgang at uiuc dot edu>)
michaelni
parents:
diff changeset
142 if (i == 1) {
6842feb093c1 rawvideo patch by (Fred Rothganger <rothgang at uiuc dot edu>)
michaelni
parents:
diff changeset
143 w >>= 1;
6842feb093c1 rawvideo patch by (Fred Rothganger <rothgang at uiuc dot edu>)
michaelni
parents:
diff changeset
144 h >>= 1;
6842feb093c1 rawvideo patch by (Fred Rothganger <rothgang at uiuc dot edu>)
michaelni
parents:
diff changeset
145 }
6842feb093c1 rawvideo patch by (Fred Rothganger <rothgang at uiuc dot edu>)
michaelni
parents:
diff changeset
146 src = picture->data[i];
6842feb093c1 rawvideo patch by (Fred Rothganger <rothgang at uiuc dot edu>)
michaelni
parents:
diff changeset
147 for(j=0;j<h;j++) {
6842feb093c1 rawvideo patch by (Fred Rothganger <rothgang at uiuc dot edu>)
michaelni
parents:
diff changeset
148 memcpy(dest, src, w);
6842feb093c1 rawvideo patch by (Fred Rothganger <rothgang at uiuc dot edu>)
michaelni
parents:
diff changeset
149 dest += w;
6842feb093c1 rawvideo patch by (Fred Rothganger <rothgang at uiuc dot edu>)
michaelni
parents:
diff changeset
150 src += picture->linesize[i];
6842feb093c1 rawvideo patch by (Fred Rothganger <rothgang at uiuc dot edu>)
michaelni
parents:
diff changeset
151 }
6842feb093c1 rawvideo patch by (Fred Rothganger <rothgang at uiuc dot edu>)
michaelni
parents:
diff changeset
152 }
6842feb093c1 rawvideo patch by (Fred Rothganger <rothgang at uiuc dot edu>)
michaelni
parents:
diff changeset
153 break;
6842feb093c1 rawvideo patch by (Fred Rothganger <rothgang at uiuc dot edu>)
michaelni
parents:
diff changeset
154 case PIX_FMT_YUV422P:
6842feb093c1 rawvideo patch by (Fred Rothganger <rothgang at uiuc dot edu>)
michaelni
parents:
diff changeset
155 for(i=0;i<3;i++) {
6842feb093c1 rawvideo patch by (Fred Rothganger <rothgang at uiuc dot edu>)
michaelni
parents:
diff changeset
156 if (i == 1) {
6842feb093c1 rawvideo patch by (Fred Rothganger <rothgang at uiuc dot edu>)
michaelni
parents:
diff changeset
157 w >>= 1;
6842feb093c1 rawvideo patch by (Fred Rothganger <rothgang at uiuc dot edu>)
michaelni
parents:
diff changeset
158 }
6842feb093c1 rawvideo patch by (Fred Rothganger <rothgang at uiuc dot edu>)
michaelni
parents:
diff changeset
159 src = picture->data[i];
6842feb093c1 rawvideo patch by (Fred Rothganger <rothgang at uiuc dot edu>)
michaelni
parents:
diff changeset
160 for(j=0;j<h;j++) {
6842feb093c1 rawvideo patch by (Fred Rothganger <rothgang at uiuc dot edu>)
michaelni
parents:
diff changeset
161 memcpy(dest, src, w);
6842feb093c1 rawvideo patch by (Fred Rothganger <rothgang at uiuc dot edu>)
michaelni
parents:
diff changeset
162 dest += w;
6842feb093c1 rawvideo patch by (Fred Rothganger <rothgang at uiuc dot edu>)
michaelni
parents:
diff changeset
163 src += picture->linesize[i];
6842feb093c1 rawvideo patch by (Fred Rothganger <rothgang at uiuc dot edu>)
michaelni
parents:
diff changeset
164 }
6842feb093c1 rawvideo patch by (Fred Rothganger <rothgang at uiuc dot edu>)
michaelni
parents:
diff changeset
165 }
6842feb093c1 rawvideo patch by (Fred Rothganger <rothgang at uiuc dot edu>)
michaelni
parents:
diff changeset
166 break;
6842feb093c1 rawvideo patch by (Fred Rothganger <rothgang at uiuc dot edu>)
michaelni
parents:
diff changeset
167 case PIX_FMT_YUV444P:
6842feb093c1 rawvideo patch by (Fred Rothganger <rothgang at uiuc dot edu>)
michaelni
parents:
diff changeset
168 for(i=0;i<3;i++) {
6842feb093c1 rawvideo patch by (Fred Rothganger <rothgang at uiuc dot edu>)
michaelni
parents:
diff changeset
169 src = picture->data[i];
6842feb093c1 rawvideo patch by (Fred Rothganger <rothgang at uiuc dot edu>)
michaelni
parents:
diff changeset
170 for(j=0;j<h;j++) {
6842feb093c1 rawvideo patch by (Fred Rothganger <rothgang at uiuc dot edu>)
michaelni
parents:
diff changeset
171 memcpy(dest, src, w);
6842feb093c1 rawvideo patch by (Fred Rothganger <rothgang at uiuc dot edu>)
michaelni
parents:
diff changeset
172 dest += w;
6842feb093c1 rawvideo patch by (Fred Rothganger <rothgang at uiuc dot edu>)
michaelni
parents:
diff changeset
173 src += picture->linesize[i];
6842feb093c1 rawvideo patch by (Fred Rothganger <rothgang at uiuc dot edu>)
michaelni
parents:
diff changeset
174 }
6842feb093c1 rawvideo patch by (Fred Rothganger <rothgang at uiuc dot edu>)
michaelni
parents:
diff changeset
175 }
6842feb093c1 rawvideo patch by (Fred Rothganger <rothgang at uiuc dot edu>)
michaelni
parents:
diff changeset
176 break;
6842feb093c1 rawvideo patch by (Fred Rothganger <rothgang at uiuc dot edu>)
michaelni
parents:
diff changeset
177 case PIX_FMT_YUV422:
6842feb093c1 rawvideo patch by (Fred Rothganger <rothgang at uiuc dot edu>)
michaelni
parents:
diff changeset
178 src = picture->data[0];
6842feb093c1 rawvideo patch by (Fred Rothganger <rothgang at uiuc dot edu>)
michaelni
parents:
diff changeset
179 for(j=0;j<h;j++) {
6842feb093c1 rawvideo patch by (Fred Rothganger <rothgang at uiuc dot edu>)
michaelni
parents:
diff changeset
180 memcpy(dest, src, w * 2);
6842feb093c1 rawvideo patch by (Fred Rothganger <rothgang at uiuc dot edu>)
michaelni
parents:
diff changeset
181 dest += w * 2;
6842feb093c1 rawvideo patch by (Fred Rothganger <rothgang at uiuc dot edu>)
michaelni
parents:
diff changeset
182 src += picture->linesize[0];
6842feb093c1 rawvideo patch by (Fred Rothganger <rothgang at uiuc dot edu>)
michaelni
parents:
diff changeset
183 }
6842feb093c1 rawvideo patch by (Fred Rothganger <rothgang at uiuc dot edu>)
michaelni
parents:
diff changeset
184 break;
6842feb093c1 rawvideo patch by (Fred Rothganger <rothgang at uiuc dot edu>)
michaelni
parents:
diff changeset
185 case PIX_FMT_RGB24:
6842feb093c1 rawvideo patch by (Fred Rothganger <rothgang at uiuc dot edu>)
michaelni
parents:
diff changeset
186 case PIX_FMT_BGR24:
6842feb093c1 rawvideo patch by (Fred Rothganger <rothgang at uiuc dot edu>)
michaelni
parents:
diff changeset
187 src = picture->data[0];
6842feb093c1 rawvideo patch by (Fred Rothganger <rothgang at uiuc dot edu>)
michaelni
parents:
diff changeset
188 for(j=0;j<h;j++) {
6842feb093c1 rawvideo patch by (Fred Rothganger <rothgang at uiuc dot edu>)
michaelni
parents:
diff changeset
189 memcpy(dest, src, w * 3);
6842feb093c1 rawvideo patch by (Fred Rothganger <rothgang at uiuc dot edu>)
michaelni
parents:
diff changeset
190 dest += w * 3;
6842feb093c1 rawvideo patch by (Fred Rothganger <rothgang at uiuc dot edu>)
michaelni
parents:
diff changeset
191 src += picture->linesize[0];
6842feb093c1 rawvideo patch by (Fred Rothganger <rothgang at uiuc dot edu>)
michaelni
parents:
diff changeset
192 }
6842feb093c1 rawvideo patch by (Fred Rothganger <rothgang at uiuc dot edu>)
michaelni
parents:
diff changeset
193 break;
6842feb093c1 rawvideo patch by (Fred Rothganger <rothgang at uiuc dot edu>)
michaelni
parents:
diff changeset
194 default:
6842feb093c1 rawvideo patch by (Fred Rothganger <rothgang at uiuc dot edu>)
michaelni
parents:
diff changeset
195 return -1;
6842feb093c1 rawvideo patch by (Fred Rothganger <rothgang at uiuc dot edu>)
michaelni
parents:
diff changeset
196 }
6842feb093c1 rawvideo patch by (Fred Rothganger <rothgang at uiuc dot edu>)
michaelni
parents:
diff changeset
197
6842feb093c1 rawvideo patch by (Fred Rothganger <rothgang at uiuc dot edu>)
michaelni
parents:
diff changeset
198 return size;
6842feb093c1 rawvideo patch by (Fred Rothganger <rothgang at uiuc dot edu>)
michaelni
parents:
diff changeset
199 }
6842feb093c1 rawvideo patch by (Fred Rothganger <rothgang at uiuc dot edu>)
michaelni
parents:
diff changeset
200
6842feb093c1 rawvideo patch by (Fred Rothganger <rothgang at uiuc dot edu>)
michaelni
parents:
diff changeset
201
6842feb093c1 rawvideo patch by (Fred Rothganger <rothgang at uiuc dot edu>)
michaelni
parents:
diff changeset
202 AVCodec rawvideo_codec = {
6842feb093c1 rawvideo patch by (Fred Rothganger <rothgang at uiuc dot edu>)
michaelni
parents:
diff changeset
203 "rawvideo",
6842feb093c1 rawvideo patch by (Fred Rothganger <rothgang at uiuc dot edu>)
michaelni
parents:
diff changeset
204 CODEC_TYPE_VIDEO,
6842feb093c1 rawvideo patch by (Fred Rothganger <rothgang at uiuc dot edu>)
michaelni
parents:
diff changeset
205 CODEC_ID_RAWVIDEO,
6842feb093c1 rawvideo patch by (Fred Rothganger <rothgang at uiuc dot edu>)
michaelni
parents:
diff changeset
206 sizeof(RawVideoContext),
6842feb093c1 rawvideo patch by (Fred Rothganger <rothgang at uiuc dot edu>)
michaelni
parents:
diff changeset
207 raw_init,
6842feb093c1 rawvideo patch by (Fred Rothganger <rothgang at uiuc dot edu>)
michaelni
parents:
diff changeset
208 raw_encode,
6842feb093c1 rawvideo patch by (Fred Rothganger <rothgang at uiuc dot edu>)
michaelni
parents:
diff changeset
209 raw_close,
6842feb093c1 rawvideo patch by (Fred Rothganger <rothgang at uiuc dot edu>)
michaelni
parents:
diff changeset
210 raw_decode,
6842feb093c1 rawvideo patch by (Fred Rothganger <rothgang at uiuc dot edu>)
michaelni
parents:
diff changeset
211 };