~medibuntu-maintainers/mplayer/medibuntu.precise

« back to all changes in this revision

Viewing changes to ffmpeg/libavformat/yuv4mpeg.c

  • Committer: Gauvain Pocentek
  • Date: 2012-03-06 11:59:12 UTC
  • mfrom: (66.1.15 precise)
  • Revision ID: gauvain@pocentek.net-20120306115912-h9d6kt9j0l532oo5
* Merge from Ubuntu:
  - put back faac support
  - recommends apport-hooks-medibuntu
  - change Maintainer, Uploaders & Vcs-* fields.
* New upstream snapshot
* upload to unstable
* Build against external libmpeg2
* drop 51_FTBFS_arm.patch again
* no longer build depend on libcdparanoia-dev on the Hurd
* Fix FTBFS on the hurd.
  Thanks to Samuel Thibault <sthibault@debian.org> (Closes: #654974)
* Fix FTBFS on arm
* New upstream snapshot, Closes: #650339, #643621, #481807
* Imported Upstream version 1.0~rc4+svn34492
* Bump standards version
* Bump dependency on libav >= 4:0.8~, Closes: #653887
* Fix build-indep
* Build mplayer-gui again, Closes: #568514
* Drop debian/all-lang-config-mak.sh, no longer needed
* include .dfsg1 in version number
* remove get-orig-source target
* no longer prune compiler flags from the environment
* No longer advertise nor build 3fdx, mga and dxr3 backends,
  Closes: #496106, #442181, #533546
* beautify mplayer version identification string
* Brown paperbag upload.
* Next try to fix build failure on sparce after recent binutils change.
* Brown paperbag upload.
* Really fix build failure on sparc after recent binutils change.
* Properly set Replaces/Conflicts on mplayer2{,-dbg} to avoid
  file overwrite errors.
* Adjust versioning of mplayer listed in the mplayer-dbg's Depends field.
* Fix build failure on sparc after recent binutils change.
* Urgency medium bumped because of RC-level bugfix
  and speeding up x264 transition.
* Update to my @debian.org email.
* Upload to unstable
* Enable joystick support on Linux only, Closes: #638408
* Rebuild fixes toolchain issue on arm, Closes: #637077
* New upstream snapshot
* following the discussion started by Diego Biurrun <diego@biurrun.de>
  in debian-devel, I have prepared a new packaging of 'mplayer'
  (with code that comes from CVS)
* the upstream tar.bz cannot be distributed by Debian, since it contains
   CSS code; so I am repackaging it 
* I have tried my best to address all known issues:
  - the package contains the detailed Copyright made by Diego Biurrun 
  - the package does not contain CSS code, or  AFAIK other code on which 
     there is active patent enforcement
  - there is a script  debian/cvs-changelog.sh  that shows all changes
     done to files included in this source.
    This should comply with GPLv2 sec 2.a  (in spirit if not in letter)
    For this reason, the source code contains CVS directories.
* needs   make (>= 3.80) for 'html-chunked-$(1)' in DOCS/xml/Makefile

* some corrections, as suggested Diego Biurrun
  - binary codecs should go into /usr/lib/codecs (upstream default)
  - better template 'mplayer/install_codecs'
  - an empty 'font=' in mplayer.conf breaks mplayer: postinst corrected
* correction in 'mplayer/cfgnote'
* better mplayer.postinst and mplayer.config

* New upstream release
* better debian/copyright file
* do not ship a skin
* New upstream release
* changed DEB_BUILD_OPTIONS to DEB_BUILD_CONFIGURE ,
  DEB_BUILD_OPTIONS is used as in debian policy
* use gcc-3.4
* changed xlibs-dev to a long list of dependencies, for Debian/etch
* try to adhere to  http://www.mplayerhq.hu/DOCS/tech/binary-packaging.txt
  (see README.Debian for details)
* removed dependency on xlibmesa-dev, disabled opengl
* New upstream release
* Simon McVittie <hacks@pseudorandom.co.uk> wonderful work:
- Work around Debian bug #267442 (glibc's sys/uio.h and gcc's altivec.h have
  conflicting uses for __vector) by re-ordering #includes
- Fix potential symlink attack in ./configure
- Disable support for binary codecs on platforms for which those codecs
  aren't available; also disable the corresponding Debconf note when it's
  inappropriate
- Changed Build-Depends: so it works in pbuilder
- Explicitly build-depend on libjpeg62-dev, libfontconfig1-dev,
  libungif4-dev 
- Tweak debian/rules to avoid certain errors being ignored
- Use --language=all
* provide a target  'debian/rules get-orig-source' 
  that recreates the orig.tar.gz ; then use the above orig.tar.gz
* rewrote some parts of debian/rules
* don't clean and recompile docs if upstream ships them
* mplayer-doc was shipping too much stuff
* translated man pages where not installed properly
* compile with libdv4-dev
* correct README.Debian
* Forgot build-dep on libtheora
* Must not depend on libxvidcore
* New upstream release
* new release.
* rc1 to become 0.90
* new pre-release
* new pre-release
* gtk bug fixed.
* new release.
* version bumped
* 0.60 pre2 release
* 0.60 pre-release.

Show diffs side-by-side

added added

removed removed

Lines of Context:
19
19
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20
20
 */
21
21
#include "avformat.h"
 
22
#include "internal.h"
22
23
 
23
24
#define Y4M_MAGIC "YUV4MPEG2"
24
25
#define Y4M_FRAME_MAGIC "FRAME"
38
39
    char inter;
39
40
    const char *colorspace = "";
40
41
 
41
 
    st = s->streams[0];
42
 
    width = st->codec->width;
 
42
    st     = s->streams[0];
 
43
    width  = st->codec->width;
43
44
    height = st->codec->height;
44
45
 
45
 
    av_reduce(&raten, &rated, st->codec->time_base.den, st->codec->time_base.num, (1UL<<31)-1);
 
46
    av_reduce(&raten, &rated, st->codec->time_base.den,
 
47
              st->codec->time_base.num, (1UL << 31) - 1);
46
48
 
47
49
    aspectn = st->sample_aspect_ratio.num;
48
50
    aspectd = st->sample_aspect_ratio.den;
49
51
 
50
 
    if ( aspectn == 0 && aspectd == 1 ) aspectd = 0;  // 0:0 means unknown
 
52
    if (aspectn == 0 && aspectd == 1)
 
53
        aspectd = 0;  // 0:0 means unknown
51
54
 
52
55
    inter = 'p'; /* progressive is the default */
53
 
    if (st->codec->coded_frame && st->codec->coded_frame->interlaced_frame) {
 
56
    if (st->codec->coded_frame && st->codec->coded_frame->interlaced_frame)
54
57
        inter = st->codec->coded_frame->top_field_first ? 't' : 'b';
55
 
    }
56
58
 
57
 
    switch(st->codec->pix_fmt) {
 
59
    switch (st->codec->pix_fmt) {
58
60
    case PIX_FMT_GRAY8:
59
61
        colorspace = " Cmono";
60
62
        break;
62
64
        colorspace = " C411 XYSCSS=411";
63
65
        break;
64
66
    case PIX_FMT_YUV420P:
65
 
        colorspace = (st->codec->chroma_sample_location == AVCHROMA_LOC_TOPLEFT)?" C420paldv XYSCSS=420PALDV":
66
 
                     (st->codec->chroma_sample_location == AVCHROMA_LOC_LEFT)   ?" C420mpeg2 XYSCSS=420MPEG2":
67
 
                     " C420jpeg XYSCSS=420JPEG";
 
67
        switch (st->codec->chroma_sample_location) {
 
68
        case AVCHROMA_LOC_TOPLEFT: colorspace = " C420paldv XYSCSS=420PALDV"; break;
 
69
        case AVCHROMA_LOC_LEFT:    colorspace = " C420mpeg2 XYSCSS=420MPEG2"; break;
 
70
        default:                   colorspace = " C420jpeg XYSCSS=420JPEG";   break;
 
71
        }
68
72
        break;
69
73
    case PIX_FMT_YUV422P:
70
74
        colorspace = " C422 XYSCSS=422";
76
80
 
77
81
    /* construct stream header, if this is the first frame */
78
82
    n = snprintf(buf, Y4M_LINE_MAX, "%s W%d H%d F%d:%d I%c A%d:%d%s\n",
79
 
                 Y4M_MAGIC,
80
 
                 width,
81
 
                 height,
82
 
                 raten, rated,
83
 
                 inter,
84
 
                 aspectn, aspectd,
85
 
                 colorspace);
 
83
                 Y4M_MAGIC, width, height, raten, rated, inter,
 
84
                 aspectn, aspectd, colorspace);
86
85
 
87
86
    return n;
88
87
}
95
94
    int* first_pkt = s->priv_data;
96
95
    int width, height, h_chroma_shift, v_chroma_shift;
97
96
    int i;
98
 
    char buf2[Y4M_LINE_MAX+1];
 
97
    char buf2[Y4M_LINE_MAX + 1];
99
98
    char buf1[20];
100
99
    uint8_t *ptr, *ptr1, *ptr2;
101
100
 
105
104
    if (*first_pkt) {
106
105
        *first_pkt = 0;
107
106
        if (yuv4_generate_header(s, buf2) < 0) {
108
 
            av_log(s, AV_LOG_ERROR, "Error. YUV4MPEG stream header write failed.\n");
 
107
            av_log(s, AV_LOG_ERROR,
 
108
                   "Error. YUV4MPEG stream header write failed.\n");
109
109
            return AVERROR(EIO);
110
110
        } else {
111
111
            avio_write(pb, buf2, strlen(buf2));
117
117
    snprintf(buf1, sizeof(buf1), "%s\n", Y4M_FRAME_MAGIC);
118
118
    avio_write(pb, buf1, strlen(buf1));
119
119
 
120
 
    width = st->codec->width;
 
120
    width  = st->codec->width;
121
121
    height = st->codec->height;
122
122
 
123
123
    ptr = picture->data[0];
124
 
    for(i=0;i<height;i++) {
 
124
    for (i = 0; i < height; i++) {
125
125
        avio_write(pb, ptr, width);
126
126
        ptr += picture->linesize[0];
127
127
    }
128
128
 
129
 
    if (st->codec->pix_fmt != PIX_FMT_GRAY8){
130
 
    // Adjust for smaller Cb and Cr planes
131
 
    avcodec_get_chroma_sub_sample(st->codec->pix_fmt, &h_chroma_shift, &v_chroma_shift);
132
 
    width >>= h_chroma_shift;
133
 
    height >>= v_chroma_shift;
 
129
    if (st->codec->pix_fmt != PIX_FMT_GRAY8) {
 
130
        // Adjust for smaller Cb and Cr planes
 
131
        avcodec_get_chroma_sub_sample(st->codec->pix_fmt, &h_chroma_shift,
 
132
                                      &v_chroma_shift);
 
133
        width  >>= h_chroma_shift;
 
134
        height >>= v_chroma_shift;
134
135
 
135
 
    ptr1 = picture->data[1];
136
 
    ptr2 = picture->data[2];
137
 
    for(i=0;i<height;i++) {     /* Cb */
138
 
        avio_write(pb, ptr1, width);
139
 
        ptr1 += picture->linesize[1];
140
 
    }
141
 
    for(i=0;i<height;i++) {     /* Cr */
142
 
        avio_write(pb, ptr2, width);
 
136
        ptr1 = picture->data[1];
 
137
        ptr2 = picture->data[2];
 
138
        for (i = 0; i < height; i++) {     /* Cb */
 
139
            avio_write(pb, ptr1, width);
 
140
            ptr1 += picture->linesize[1];
 
141
        }
 
142
        for (i = 0; i < height; i++) {     /* Cr */
 
143
            avio_write(pb, ptr2, width);
143
144
            ptr2 += picture->linesize[2];
144
 
    }
 
145
        }
145
146
    }
146
147
    avio_flush(pb);
147
148
    return 0;
149
150
 
150
151
static int yuv4_write_header(AVFormatContext *s)
151
152
{
152
 
    int* first_pkt = s->priv_data;
 
153
    int *first_pkt = s->priv_data;
153
154
 
154
155
    if (s->nb_streams != 1)
155
156
        return AVERROR(EIO);
156
157
 
157
158
    if (s->streams[0]->codec->pix_fmt == PIX_FMT_YUV411P) {
158
 
        av_log(s, AV_LOG_ERROR, "Warning: generating rarely used 4:1:1 YUV stream, some mjpegtools might not work.\n");
159
 
    }
160
 
    else if ((s->streams[0]->codec->pix_fmt != PIX_FMT_YUV420P) &&
161
 
             (s->streams[0]->codec->pix_fmt != PIX_FMT_YUV422P) &&
162
 
             (s->streams[0]->codec->pix_fmt != PIX_FMT_GRAY8) &&
163
 
             (s->streams[0]->codec->pix_fmt != PIX_FMT_YUV444P)) {
164
 
        av_log(s, AV_LOG_ERROR, "ERROR: yuv4mpeg only handles yuv444p, yuv422p, yuv420p, yuv411p and gray pixel formats. Use -pix_fmt to select one.\n");
 
159
        av_log(s, AV_LOG_ERROR, "Warning: generating rarely used 4:1:1 YUV "
 
160
               "stream, some mjpegtools might not work.\n");
 
161
    } else if ((s->streams[0]->codec->pix_fmt != PIX_FMT_YUV420P) &&
 
162
               (s->streams[0]->codec->pix_fmt != PIX_FMT_YUV422P) &&
 
163
               (s->streams[0]->codec->pix_fmt != PIX_FMT_GRAY8)   &&
 
164
               (s->streams[0]->codec->pix_fmt != PIX_FMT_YUV444P)) {
 
165
        av_log(s, AV_LOG_ERROR, "ERROR: yuv4mpeg only handles yuv444p, "
 
166
               "yuv422p, yuv420p, yuv411p and gray pixel formats. "
 
167
               "Use -pix_fmt to select one.\n");
165
168
        return AVERROR(EIO);
166
169
    }
167
170
 
170
173
}
171
174
 
172
175
AVOutputFormat ff_yuv4mpegpipe_muxer = {
173
 
    "yuv4mpegpipe",
174
 
    NULL_IF_CONFIG_SMALL("YUV4MPEG pipe format"),
175
 
    "",
176
 
    "y4m",
177
 
    sizeof(int),
178
 
    CODEC_ID_NONE,
179
 
    CODEC_ID_RAWVIDEO,
180
 
    yuv4_write_header,
181
 
    yuv4_write_packet,
182
 
    .flags = AVFMT_RAWPICTURE,
 
176
    .name              = "yuv4mpegpipe",
 
177
    .long_name         = NULL_IF_CONFIG_SMALL("YUV4MPEG pipe format"),
 
178
    .mime_type         = "",
 
179
    .extensions        = "y4m",
 
180
    .priv_data_size    = sizeof(int),
 
181
    .audio_codec       = CODEC_ID_NONE,
 
182
    .video_codec       = CODEC_ID_RAWVIDEO,
 
183
    .write_header      = yuv4_write_header,
 
184
    .write_packet      = yuv4_write_packet,
 
185
    .flags             = AVFMT_RAWPICTURE,
183
186
};
184
187
#endif
185
188
 
189
192
 
190
193
static int yuv4_read_header(AVFormatContext *s, AVFormatParameters *ap)
191
194
{
192
 
    char header[MAX_YUV4_HEADER+10];  // Include headroom for the longest option
193
 
    char *tokstart,*tokend,*header_end;
 
195
    char header[MAX_YUV4_HEADER + 10];  // Include headroom for
 
196
                                        // the longest option
 
197
    char *tokstart, *tokend, *header_end;
194
198
    int i;
195
199
    AVIOContext *pb = s->pb;
196
 
    int width=-1, height=-1, raten=0, rated=0, aspectn=0, aspectd=0;
197
 
    enum PixelFormat pix_fmt=PIX_FMT_NONE,alt_pix_fmt=PIX_FMT_NONE;
 
200
    int width = -1, height  = -1, raten   = 0,
 
201
        rated =  0, aspectn =  0, aspectd = 0;
 
202
    enum PixelFormat pix_fmt = PIX_FMT_NONE, alt_pix_fmt = PIX_FMT_NONE;
198
203
    enum AVChromaLocation chroma_sample_location = AVCHROMA_LOC_UNSPECIFIED;
199
204
    AVStream *st;
200
205
    struct frame_attributes *s1 = s->priv_data;
201
206
 
202
 
    for (i=0; i<MAX_YUV4_HEADER; i++) {
 
207
    for (i = 0; i < MAX_YUV4_HEADER; i++) {
203
208
        header[i] = avio_r8(pb);
204
209
        if (header[i] == '\n') {
205
 
            header[i+1] = 0x20;  // Add a space after last option. Makes parsing "444" vs "444alpha" easier.
206
 
            header[i+2] = 0;
 
210
            header[i + 1] = 0x20;  // Add a space after last option.
 
211
                                   // Makes parsing "444" vs "444alpha" easier.
 
212
            header[i + 2] = 0;
207
213
            break;
208
214
        }
209
215
    }
210
 
    if (i == MAX_YUV4_HEADER) return -1;
211
 
    if (strncmp(header, Y4M_MAGIC, strlen(Y4M_MAGIC))) return -1;
 
216
    if (i == MAX_YUV4_HEADER)
 
217
        return -1;
 
218
    if (strncmp(header, Y4M_MAGIC, strlen(Y4M_MAGIC)))
 
219
        return -1;
212
220
 
213
221
    s1->interlaced_frame = 0;
214
222
    s1->top_field_first = 0;
215
 
    header_end = &header[i+1]; // Include space
216
 
    for(tokstart = &header[strlen(Y4M_MAGIC) + 1]; tokstart < header_end; tokstart++) {
217
 
        if (*tokstart==0x20) continue;
 
223
    header_end = &header[i + 1]; // Include space
 
224
    for (tokstart = &header[strlen(Y4M_MAGIC) + 1];
 
225
         tokstart < header_end; tokstart++) {
 
226
        if (*tokstart == 0x20)
 
227
            continue;
218
228
        switch (*tokstart++) {
219
229
        case 'W': // Width. Required.
220
 
            width = strtol(tokstart, &tokend, 10);
221
 
            tokstart=tokend;
 
230
            width    = strtol(tokstart, &tokend, 10);
 
231
            tokstart = tokend;
222
232
            break;
223
233
        case 'H': // Height. Required.
224
 
            height = strtol(tokstart, &tokend, 10);
225
 
            tokstart=tokend;
 
234
            height   = strtol(tokstart, &tokend, 10);
 
235
            tokstart = tokend;
226
236
            break;
227
237
        case 'C': // Color space
228
 
            if (strncmp("420jpeg",tokstart,7)==0) {
 
238
            if (strncmp("420jpeg", tokstart, 7) == 0) {
229
239
                pix_fmt = PIX_FMT_YUV420P;
230
240
                chroma_sample_location = AVCHROMA_LOC_CENTER;
231
 
            } else if (strncmp("420mpeg2",tokstart,8)==0) {
 
241
            } else if (strncmp("420mpeg2", tokstart, 8) == 0) {
232
242
                pix_fmt = PIX_FMT_YUV420P;
233
243
                chroma_sample_location = AVCHROMA_LOC_LEFT;
234
 
            } else if (strncmp("420paldv", tokstart, 8)==0) {
 
244
            } else if (strncmp("420paldv", tokstart, 8) == 0) {
235
245
                pix_fmt = PIX_FMT_YUV420P;
236
246
                chroma_sample_location = AVCHROMA_LOC_TOPLEFT;
237
 
            } else if (strncmp("411", tokstart, 3)==0)
 
247
            } else if (strncmp("411", tokstart, 3) == 0)
238
248
                pix_fmt = PIX_FMT_YUV411P;
239
 
            else if (strncmp("422", tokstart, 3)==0)
 
249
            else if (strncmp("422", tokstart, 3) == 0)
240
250
                pix_fmt = PIX_FMT_YUV422P;
241
 
            else if (strncmp("444alpha", tokstart, 8)==0) {
242
 
                av_log(s, AV_LOG_ERROR, "Cannot handle 4:4:4:4 YUV4MPEG stream.\n");
 
251
            else if (strncmp("444alpha", tokstart, 8) == 0 ) {
 
252
                av_log(s, AV_LOG_ERROR, "Cannot handle 4:4:4:4 "
 
253
                       "YUV4MPEG stream.\n");
243
254
                return -1;
244
 
            } else if (strncmp("444", tokstart, 3)==0)
 
255
            } else if (strncmp("444", tokstart, 3) == 0)
245
256
                pix_fmt = PIX_FMT_YUV444P;
246
 
            else if (strncmp("mono",tokstart, 4)==0) {
 
257
            else if (strncmp("mono", tokstart, 4) == 0) {
247
258
                pix_fmt = PIX_FMT_GRAY8;
248
259
            } else {
249
 
                av_log(s, AV_LOG_ERROR, "YUV4MPEG stream contains an unknown pixel format.\n");
 
260
                av_log(s, AV_LOG_ERROR, "YUV4MPEG stream contains an unknown "
 
261
                       "pixel format.\n");
250
262
                return -1;
251
263
            }
252
 
            while(tokstart<header_end&&*tokstart!=0x20) tokstart++;
 
264
            while (tokstart < header_end && *tokstart != 0x20)
 
265
                tokstart++;
253
266
            break;
254
267
        case 'I': // Interlace type
255
268
            switch (*tokstart++){
256
269
            case '?':
257
270
                break;
258
271
            case 'p':
259
 
                s1->interlaced_frame=0;
 
272
                s1->interlaced_frame = 0;
260
273
                break;
261
274
            case 't':
262
 
                s1->interlaced_frame=1;
263
 
                s1->top_field_first=1;
 
275
                s1->interlaced_frame = 1;
 
276
                s1->top_field_first = 1;
264
277
                break;
265
278
            case 'b':
266
 
                s1->interlaced_frame=1;
267
 
                s1->top_field_first=0;
 
279
                s1->interlaced_frame = 1;
 
280
                s1->top_field_first = 0;
268
281
                break;
269
282
            case 'm':
270
 
                av_log(s, AV_LOG_ERROR, "YUV4MPEG stream contains mixed interlaced and non-interlaced frames.\n");
 
283
                av_log(s, AV_LOG_ERROR, "YUV4MPEG stream contains mixed "
 
284
                       "interlaced and non-interlaced frames.\n");
271
285
                return -1;
272
286
            default:
273
287
                av_log(s, AV_LOG_ERROR, "YUV4MPEG has invalid header.\n");
275
289
            }
276
290
            break;
277
291
        case 'F': // Frame rate
278
 
            sscanf(tokstart,"%d:%d",&raten,&rated); // 0:0 if unknown
279
 
            while(tokstart<header_end&&*tokstart!=0x20) tokstart++;
 
292
            sscanf(tokstart, "%d:%d", &raten, &rated); // 0:0 if unknown
 
293
            while (tokstart < header_end && *tokstart != 0x20)
 
294
                tokstart++;
280
295
            break;
281
296
        case 'A': // Pixel aspect
282
 
            sscanf(tokstart,"%d:%d",&aspectn,&aspectd); // 0:0 if unknown
283
 
            while(tokstart<header_end&&*tokstart!=0x20) tokstart++;
 
297
            sscanf(tokstart, "%d:%d", &aspectn, &aspectd); // 0:0 if unknown
 
298
            while (tokstart < header_end && *tokstart != 0x20)
 
299
                tokstart++;
284
300
            break;
285
301
        case 'X': // Vendor extensions
286
 
            if (strncmp("YSCSS=",tokstart,6)==0) {
 
302
            if (strncmp("YSCSS=", tokstart, 6) == 0) {
287
303
                // Older nonstandard pixel format representation
288
 
                tokstart+=6;
289
 
                if (strncmp("420JPEG",tokstart,7)==0)
290
 
                    alt_pix_fmt=PIX_FMT_YUV420P;
291
 
                else if (strncmp("420MPEG2",tokstart,8)==0)
292
 
                    alt_pix_fmt=PIX_FMT_YUV420P;
293
 
                else if (strncmp("420PALDV",tokstart,8)==0)
294
 
                    alt_pix_fmt=PIX_FMT_YUV420P;
295
 
                else if (strncmp("411",tokstart,3)==0)
296
 
                    alt_pix_fmt=PIX_FMT_YUV411P;
297
 
                else if (strncmp("422",tokstart,3)==0)
298
 
                    alt_pix_fmt=PIX_FMT_YUV422P;
299
 
                else if (strncmp("444",tokstart,3)==0)
300
 
                    alt_pix_fmt=PIX_FMT_YUV444P;
 
304
                tokstart += 6;
 
305
                if (strncmp("420JPEG", tokstart, 7) == 0)
 
306
                    alt_pix_fmt = PIX_FMT_YUV420P;
 
307
                else if (strncmp("420MPEG2", tokstart, 8) == 0)
 
308
                    alt_pix_fmt = PIX_FMT_YUV420P;
 
309
                else if (strncmp("420PALDV", tokstart, 8) == 0)
 
310
                    alt_pix_fmt = PIX_FMT_YUV420P;
 
311
                else if (strncmp("411", tokstart, 3) == 0)
 
312
                    alt_pix_fmt = PIX_FMT_YUV411P;
 
313
                else if (strncmp("422", tokstart, 3) == 0)
 
314
                    alt_pix_fmt = PIX_FMT_YUV422P;
 
315
                else if (strncmp("444", tokstart, 3) == 0)
 
316
                    alt_pix_fmt = PIX_FMT_YUV444P;
301
317
            }
302
 
            while(tokstart<header_end&&*tokstart!=0x20) tokstart++;
 
318
            while (tokstart < header_end && *tokstart != 0x20)
 
319
                tokstart++;
303
320
            break;
304
321
        }
305
322
    }
306
323
 
307
 
    if ((width == -1) || (height == -1)) {
 
324
    if (width == -1 || height == -1) {
308
325
        av_log(s, AV_LOG_ERROR, "YUV4MPEG has invalid header.\n");
309
326
        return -1;
310
327
    }
327
344
        aspectd = 1;
328
345
    }
329
346
 
330
 
    st = av_new_stream(s, 0);
331
 
    if(!st)
 
347
    st = avformat_new_stream(s, NULL);
 
348
    if (!st)
332
349
        return AVERROR(ENOMEM);
333
 
    st->codec->width = width;
 
350
    st->codec->width  = width;
334
351
    st->codec->height = height;
335
 
    av_reduce(&raten, &rated, raten, rated, (1UL<<31)-1);
336
 
    av_set_pts_info(st, 64, rated, raten);
337
 
    st->codec->pix_fmt = pix_fmt;
338
 
    st->codec->codec_type = AVMEDIA_TYPE_VIDEO;
339
 
    st->codec->codec_id = CODEC_ID_RAWVIDEO;
340
 
    st->sample_aspect_ratio= (AVRational){aspectn, aspectd};
 
352
    av_reduce(&raten, &rated, raten, rated, (1UL << 31) - 1);
 
353
    avpriv_set_pts_info(st, 64, rated, raten);
 
354
    st->codec->pix_fmt                = pix_fmt;
 
355
    st->codec->codec_type             = AVMEDIA_TYPE_VIDEO;
 
356
    st->codec->codec_id               = CODEC_ID_RAWVIDEO;
 
357
    st->sample_aspect_ratio           = (AVRational){ aspectn, aspectd };
341
358
    st->codec->chroma_sample_location = chroma_sample_location;
342
359
 
343
360
    return 0;
351
368
    AVStream *st = s->streams[0];
352
369
    struct frame_attributes *s1 = s->priv_data;
353
370
 
354
 
    for (i=0; i<MAX_FRAME_HEADER; i++) {
 
371
    for (i = 0; i < MAX_FRAME_HEADER; i++) {
355
372
        header[i] = avio_r8(s->pb);
356
373
        if (header[i] == '\n') {
357
 
            header[i+1] = 0;
 
374
            header[i + 1] = 0;
358
375
            break;
359
376
        }
360
377
    }
361
 
    if (i == MAX_FRAME_HEADER) return -1;
362
 
    if (strncmp(header, Y4M_FRAME_MAGIC, strlen(Y4M_FRAME_MAGIC))) return -1;
 
378
    if (i == MAX_FRAME_HEADER)
 
379
        return -1;
 
380
    if (strncmp(header, Y4M_FRAME_MAGIC, strlen(Y4M_FRAME_MAGIC)))
 
381
        return -1;
363
382
 
364
 
    width = st->codec->width;
 
383
    width  = st->codec->width;
365
384
    height = st->codec->height;
366
385
 
367
386
    packet_size = avpicture_get_size(st->codec->pix_fmt, width, height);
371
390
    if (av_get_packet(s->pb, pkt, packet_size) != packet_size)
372
391
        return AVERROR(EIO);
373
392
 
374
 
    if (s->streams[0]->codec->coded_frame) {
375
 
        s->streams[0]->codec->coded_frame->interlaced_frame = s1->interlaced_frame;
376
 
        s->streams[0]->codec->coded_frame->top_field_first = s1->top_field_first;
 
393
    if (st->codec->coded_frame) {
 
394
        st->codec->coded_frame->interlaced_frame = s1->interlaced_frame;
 
395
        st->codec->coded_frame->top_field_first  = s1->top_field_first;
377
396
    }
378
397
 
379
398
    pkt->stream_index = 0;
383
402
static int yuv4_probe(AVProbeData *pd)
384
403
{
385
404
    /* check file header */
386
 
    if (strncmp(pd->buf, Y4M_MAGIC, sizeof(Y4M_MAGIC)-1)==0)
 
405
    if (strncmp(pd->buf, Y4M_MAGIC, sizeof(Y4M_MAGIC) - 1) == 0)
387
406
        return AVPROBE_SCORE_MAX;
388
407
    else
389
408
        return 0;
391
410
 
392
411
#if CONFIG_YUV4MPEGPIPE_DEMUXER
393
412
AVInputFormat ff_yuv4mpegpipe_demuxer = {
394
 
    "yuv4mpegpipe",
395
 
    NULL_IF_CONFIG_SMALL("YUV4MPEG pipe format"),
396
 
    sizeof(struct frame_attributes),
397
 
    yuv4_probe,
398
 
    yuv4_read_header,
399
 
    yuv4_read_packet,
400
 
    .extensions = "y4m"
 
413
    .name           = "yuv4mpegpipe",
 
414
    .long_name      = NULL_IF_CONFIG_SMALL("YUV4MPEG pipe format"),
 
415
    .priv_data_size = sizeof(struct frame_attributes),
 
416
    .read_probe     = yuv4_probe,
 
417
    .read_header    = yuv4_read_header,
 
418
    .read_packet    = yuv4_read_packet,
 
419
    .extensions     = "y4m"
401
420
};
402
421
#endif