af_scaletempo: reset latency info when reconfiguring
[mplayer.git] / libmpdemux / yuv4mpeg.c
blob1606faa41ba3b16c72b1a8557754263d2f4a08e5
1 /*
2 * yuv4mpeg.c: Functions for reading and writing "new" YUV4MPEG streams
4 * Copyright (C) 2001 Matthew J. Marjanovic <maddog@mir.com>
6 * This file is part of the MJPEG Tools package (mjpeg.sourceforge.net).
7 * Ported to mplayer by Rik Snel <rsnel@cube.dyndns.org>
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License
11 * as published by the Free Software Foundation; either version 2
12 * of the License, or (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
25 #include "config.h"
27 #include <unistd.h>
28 #include <stdio.h>
29 #include <stdlib.h>
30 #include <string.h>
31 #include "yuv4mpeg.h"
32 #include "yuv4mpeg_intern.h"
33 #include "mp_msg.h"
34 #include "libavutil/attributes.h"
36 static int _y4mparam_allow_unknown_tags = 1; /* default is forgiveness */
38 static void *(*_y4m_alloc)(size_t bytes) = malloc;
39 static void (*_y4m_free)(void *ptr) = free;
41 int y4m_allow_unknown_tags(int yn) {
42 int old = _y4mparam_allow_unknown_tags;
43 if (yn >= 0) _y4mparam_allow_unknown_tags = (yn) ? 1 : 0;
44 return old;
49 /*************************************************************************
51 * Convenience functions for fd read/write
53 * - guaranteed to transfer entire payload (or fail)
54 * - returns:
55 * 0 on complete success
56 * +(# of remaining bytes) on eof (for y4m_read)
57 * -(# of rem. bytes) on error (and ERRNO should be set)
59 *************************************************************************/
62 ssize_t y4m_read(stream_t *s, char *buf, size_t len)
64 ssize_t n;
66 while (len > 0) {
67 n = stream_read(s, buf, len);
68 if (n <= 0) {
69 /* return amount left to read */
70 if (n == 0)
71 return len; /* n == 0 --> eof */
72 else
73 return -len; /* n < 0 --> error */
75 buf += n;
76 len -= n;
78 return 0;
82 #if 0 /* not needed */
83 ssize_t y4m_write(int fd, char *buf, size_t len)
85 ssize_t n;
87 while (len > 0) {
88 n = write(fd, buf, len);
89 if (n < 0) return -len; /* return amount left to write */
90 buf += n;
91 len -= n;
93 return 0;
95 #endif
98 /*************************************************************************
100 * "Extra tags" handling
102 *************************************************************************/
105 static char *y4m_new_xtag(void)
107 return _y4m_alloc(Y4M_MAX_XTAG_SIZE);
111 void y4m_init_xtag_list(y4m_xtag_list_t *xtags)
113 int i;
114 xtags->count = 0;
115 for (i = 0; i < Y4M_MAX_XTAGS; i++) {
116 xtags->tags[i] = NULL;
121 void y4m_fini_xtag_list(y4m_xtag_list_t *xtags)
123 int i;
124 for (i = 0; i < Y4M_MAX_XTAGS; i++) {
125 if (xtags->tags[i] != NULL) {
126 _y4m_free(xtags->tags[i]);
127 xtags->tags[i] = NULL;
130 xtags->count = 0;
134 void y4m_copy_xtag_list(y4m_xtag_list_t *dest, const y4m_xtag_list_t *src)
136 int i;
137 for (i = 0; i < src->count; i++) {
138 if (dest->tags[i] == NULL)
139 dest->tags[i] = y4m_new_xtag();
140 strncpy(dest->tags[i], src->tags[i], Y4M_MAX_XTAG_SIZE);
142 dest->count = src->count;
147 #if 0
148 static int y4m_snprint_xtags(char *s, int maxn, y4m_xtag_list_t *xtags)
150 int i, room;
152 for (i = 0, room = maxn - 1; i < xtags->count; i++) {
153 int n = snprintf(s, room + 1, " %s", xtags->tags[i]);
154 if ((n < 0) || (n > room)) return Y4M_ERR_HEADER;
155 s += n;
156 room -= n;
158 s[0] = '\n'; /* finish off header with newline */
159 s[1] = '\0'; /* ...and end-of-string */
160 return Y4M_OK;
162 #endif
165 int y4m_xtag_count(const y4m_xtag_list_t *xtags)
167 return xtags->count;
171 const char *y4m_xtag_get(const y4m_xtag_list_t *xtags, int n)
173 if (n >= xtags->count)
174 return NULL;
175 else
176 return xtags->tags[n];
180 int y4m_xtag_add(y4m_xtag_list_t *xtags, const char *tag)
182 if (xtags->count >= Y4M_MAX_XTAGS) return Y4M_ERR_XXTAGS;
183 if (xtags->tags[xtags->count] == NULL) {
184 xtags->tags[xtags->count] = y4m_new_xtag();
186 strncpy(xtags->tags[xtags->count], tag, Y4M_MAX_XTAG_SIZE);
187 (xtags->count)++;
188 return Y4M_OK;
192 int y4m_xtag_remove(y4m_xtag_list_t *xtags, int n)
194 int i;
195 char *q;
197 if ((n < 0) || (n >= xtags->count)) return Y4M_ERR_RANGE;
198 q = xtags->tags[n];
199 for (i = n; i < (xtags->count - 1); i++)
200 xtags->tags[i] = xtags->tags[i+1];
201 xtags->tags[i] = q;
202 (xtags->count)--;
203 return Y4M_OK;
207 int y4m_xtag_clearlist(y4m_xtag_list_t *xtags)
209 xtags->count = 0;
210 return Y4M_OK;
214 int y4m_xtag_addlist(y4m_xtag_list_t *dest, const y4m_xtag_list_t *src)
216 int i, j;
218 if ((dest->count + src->count) > Y4M_MAX_XTAGS) return Y4M_ERR_XXTAGS;
219 for (i = dest->count, j = 0;
220 j < src->count;
221 i++, j++) {
222 if (dest->tags[i] == NULL)
223 dest->tags[i] = y4m_new_xtag();
224 strncpy(dest->tags[i], src->tags[i], Y4M_MAX_XTAG_SIZE);
226 dest->count += src->count;
227 return Y4M_OK;
231 /*************************************************************************
233 * Creators/destructors for y4m_*_info_t structures
235 *************************************************************************/
238 void y4m_init_stream_info(y4m_stream_info_t *info)
240 if (info == NULL) return;
241 /* initialize info */
242 info->width = Y4M_UNKNOWN;
243 info->height = Y4M_UNKNOWN;
244 info->interlace = Y4M_UNKNOWN;
245 info->framerate = y4m_fps_UNKNOWN;
246 info->sampleaspect = y4m_sar_UNKNOWN;
247 y4m_init_xtag_list(&(info->x_tags));
251 void y4m_copy_stream_info(y4m_stream_info_t *dest, y4m_stream_info_t *src)
253 if ((dest == NULL) || (src == NULL)) return;
254 /* copy info */
255 dest->width = src->width;
256 dest->height = src->height;
257 dest->interlace = src->interlace;
258 dest->framerate = src->framerate;
259 dest->sampleaspect = src->sampleaspect;
260 y4m_copy_xtag_list(&(dest->x_tags), &(src->x_tags));
264 void y4m_fini_stream_info(y4m_stream_info_t *info)
266 if (info == NULL) return;
267 y4m_fini_xtag_list(&(info->x_tags));
271 void y4m_si_set_width(y4m_stream_info_t *si, int width)
273 si->width = width;
274 si->framelength = (si->height * si->width) * 3 / 2;
277 int y4m_si_get_width(y4m_stream_info_t *si)
278 { return si->width; }
280 void y4m_si_set_height(y4m_stream_info_t *si, int height)
282 si->height = height;
283 si->framelength = (si->height * si->width) * 3 / 2;
286 int y4m_si_get_height(y4m_stream_info_t *si)
287 { return si->height; }
289 void y4m_si_set_interlace(y4m_stream_info_t *si, int interlace)
290 { si->interlace = interlace; }
292 int y4m_si_get_interlace(y4m_stream_info_t *si)
293 { return si->interlace; }
295 void y4m_si_set_framerate(y4m_stream_info_t *si, y4m_ratio_t framerate)
296 { si->framerate = framerate; }
298 y4m_ratio_t y4m_si_get_framerate(y4m_stream_info_t *si)
299 { return si->framerate; }
301 void y4m_si_set_sampleaspect(y4m_stream_info_t *si, y4m_ratio_t sar)
302 { si->sampleaspect = sar; }
304 y4m_ratio_t y4m_si_get_sampleaspect(y4m_stream_info_t *si)
305 { return si->sampleaspect; }
307 int y4m_si_get_framelength(y4m_stream_info_t *si)
308 { return si->framelength; }
310 y4m_xtag_list_t *y4m_si_xtags(y4m_stream_info_t *si)
311 { return &(si->x_tags); }
315 void y4m_init_frame_info(y4m_frame_info_t *info)
317 if (info == NULL) return;
318 /* initialize info */
319 y4m_init_xtag_list(&(info->x_tags));
323 void y4m_copy_frame_info(y4m_frame_info_t *dest, y4m_frame_info_t *src)
325 if ((dest == NULL) || (src == NULL)) return;
326 /* copy info */
327 y4m_copy_xtag_list(&(dest->x_tags), &(src->x_tags));
331 void y4m_fini_frame_info(y4m_frame_info_t *info)
333 if (info == NULL) return;
334 y4m_fini_xtag_list(&(info->x_tags));
339 /*************************************************************************
341 * Tag parsing
343 *************************************************************************/
345 int y4m_parse_stream_tags(char *s, y4m_stream_info_t *i)
347 char *token, *value;
348 char tag;
349 int err;
351 /* parse fields */
352 for (token = strtok(s, Y4M_DELIM);
353 token != NULL;
354 token = strtok(NULL, Y4M_DELIM)) {
355 if (token[0] == '\0') continue; /* skip empty strings */
356 tag = token[0];
357 value = token + 1;
358 switch (tag) {
359 case 'W': /* width */
360 i->width = atoi(value);
361 if (i->width <= 0) return Y4M_ERR_RANGE;
362 break;
363 case 'H': /* height */
364 i->height = atoi(value);
365 if (i->height <= 0) return Y4M_ERR_RANGE;
366 break;
367 case 'F': /* frame rate (fps) */
368 if ((err = y4m_parse_ratio(&(i->framerate), value)) != Y4M_OK)
369 return err;
370 if (i->framerate.n < 0) return Y4M_ERR_RANGE;
371 break;
372 case 'I': /* interlacing */
373 switch (value[0]) {
374 case 'p': i->interlace = Y4M_ILACE_NONE; break;
375 case 't': i->interlace = Y4M_ILACE_TOP_FIRST; break;
376 case 'b': i->interlace = Y4M_ILACE_BOTTOM_FIRST; break;
377 case '?':
378 default:
379 i->interlace = Y4M_UNKNOWN; break;
381 break;
382 case 'A': /* sample (pixel) aspect ratio */
383 if ((err = y4m_parse_ratio(&(i->sampleaspect), value)) != Y4M_OK)
384 return err;
385 if (i->sampleaspect.n < 0) return Y4M_ERR_RANGE;
386 break;
387 case 'X': /* 'X' meta-tag */
388 if ((err = y4m_xtag_add(&(i->x_tags), token)) != Y4M_OK) return err;
389 break;
390 default:
391 /* possible error on unknown options */
392 if (_y4mparam_allow_unknown_tags) {
393 /* unknown tags ok: store in xtag list and warn... */
394 if ((err = y4m_xtag_add(&(i->x_tags), token)) != Y4M_OK) return err;
395 mp_msg(MSGT_DEMUX, MSGL_WARN, "Unknown stream tag encountered: '%s'\n", token);
396 } else {
397 /* unknown tags are *not* ok */
398 return Y4M_ERR_BADTAG;
400 break;
403 /* Error checking... width and height must be known since we can't
404 * parse without them
406 if( i->width == Y4M_UNKNOWN || i->height == Y4M_UNKNOWN )
407 return Y4M_ERR_HEADER;
408 /* ta da! done. */
409 return Y4M_OK;
414 static int y4m_parse_frame_tags(char *s, y4m_frame_info_t *i)
416 char *token, *value av_unused;
417 char tag;
418 int err;
420 /* parse fields */
421 for (token = strtok(s, Y4M_DELIM);
422 token != NULL;
423 token = strtok(NULL, Y4M_DELIM)) {
424 if (token[0] == '\0') continue; /* skip empty strings */
425 tag = token[0];
426 value = token + 1;
427 switch (tag) {
428 case 'X': /* 'X' meta-tag */
429 if ((err = y4m_xtag_add(&(i->x_tags), token)) != Y4M_OK) return err;
430 break;
431 default:
432 /* possible error on unknown options */
433 if (_y4mparam_allow_unknown_tags) {
434 /* unknown tags ok: store in xtag list and warn... */
435 if ((err = y4m_xtag_add(&(i->x_tags), token)) != Y4M_OK) return err;
436 mp_msg(MSGT_DEMUX, MSGL_WARN, "Unknown frame tag encountered: '%s'\n", token);
437 } else {
438 /* unknown tags are *not* ok */
439 return Y4M_ERR_BADTAG;
441 break;
444 /* ta da! done. */
445 return Y4M_OK;
452 /*************************************************************************
454 * Read/Write stream header
456 *************************************************************************/
459 int y4m_read_stream_header(stream_t *s, y4m_stream_info_t *i)
461 char line[Y4M_LINE_MAX];
462 char *p;
463 int n;
464 int err;
466 /* read the header line */
467 for (n = 0, p = line; n < Y4M_LINE_MAX; n++, p++) {
468 if (y4m_read(s, p, 1))
469 return Y4M_ERR_SYSTEM;
470 if (*p == '\n') {
471 *p = '\0'; /* Replace linefeed by end of string */
472 break;
475 if (n >= Y4M_LINE_MAX)
476 return Y4M_ERR_HEADER;
477 /* look for keyword in header */
478 if (strncmp(line, Y4M_MAGIC, strlen(Y4M_MAGIC)))
479 return Y4M_ERR_MAGIC;
480 if ((err = y4m_parse_stream_tags(line + strlen(Y4M_MAGIC), i)) != Y4M_OK)
481 return err;
483 i->framelength = (i->height * i->width) * 3 / 2;
484 return Y4M_OK;
488 #if 0
489 int y4m_write_stream_header(int fd, y4m_stream_info_t *i)
491 char s[Y4M_LINE_MAX+1];
492 int n;
493 int err;
495 y4m_ratio_reduce(&(i->framerate));
496 y4m_ratio_reduce(&(i->sampleaspect));
497 n = snprintf(s, sizeof(s), "%s W%d H%d F%d:%d I%s A%d:%d",
498 Y4M_MAGIC,
499 i->width,
500 i->height,
501 i->framerate.n, i->framerate.d,
502 (i->interlace == Y4M_ILACE_NONE) ? "p" :
503 (i->interlace == Y4M_ILACE_TOP_FIRST) ? "t" :
504 (i->interlace == Y4M_ILACE_BOTTOM_FIRST) ? "b" : "?",
505 i->sampleaspect.n, i->sampleaspect.d);
506 if ((n < 0) || (n > Y4M_LINE_MAX)) return Y4M_ERR_HEADER;
507 if ((err = y4m_snprint_xtags(s + n, sizeof(s) - n - 1, &(i->x_tags)))
508 != Y4M_OK)
509 return err;
510 /* non-zero on error */
511 return (y4m_write(fd, s, strlen(s)) ? Y4M_ERR_SYSTEM : Y4M_OK);
513 #endif
518 /*************************************************************************
520 * Read/Write frame header
522 *************************************************************************/
524 int y4m_read_frame_header(stream_t *s, y4m_frame_info_t *i)
526 char line[Y4M_LINE_MAX];
527 char *p;
528 int n;
529 ssize_t remain;
531 /* This is more clever than read_stream_header...
532 Try to read "FRAME\n" all at once, and don't try to parse
533 if nothing else is there...
535 remain = y4m_read(s, line, sizeof(Y4M_FRAME_MAGIC));
536 if (remain != 0)
538 /* A clean EOF should end exactly at a frame-boundary */
539 if( remain == sizeof(Y4M_FRAME_MAGIC) )
540 return Y4M_ERR_EOF;
541 else
542 return Y4M_ERR_SYSTEM;
544 if (strncmp(line, Y4M_FRAME_MAGIC, sizeof(Y4M_FRAME_MAGIC)-1))
545 return Y4M_ERR_MAGIC;
546 if (line[sizeof(Y4M_FRAME_MAGIC)-1] == '\n')
547 return Y4M_OK; /* done -- no tags: that was the end-of-line. */
549 if (line[sizeof(Y4M_FRAME_MAGIC)-1] != Y4M_DELIM[0]) {
550 return Y4M_ERR_MAGIC; /* wasn't a space -- what was it? */
553 /* proceed to get the tags... (overwrite the magic) */
554 for (n = 0, p = line; n < Y4M_LINE_MAX; n++, p++) {
555 if (y4m_read(s, p, 1))
556 return Y4M_ERR_SYSTEM;
557 if (*p == '\n') {
558 *p = '\0'; /* Replace linefeed by end of string */
559 break;
562 if (n >= Y4M_LINE_MAX) return Y4M_ERR_HEADER;
563 /* non-zero on error */
564 return y4m_parse_frame_tags(line, i);
568 #if 0
569 int y4m_write_frame_header(int fd, y4m_frame_info_t *i)
571 char s[Y4M_LINE_MAX+1];
572 int n;
573 int err;
575 n = snprintf(s, sizeof(s), "%s", Y4M_FRAME_MAGIC);
576 if ((n < 0) || (n > Y4M_LINE_MAX)) return Y4M_ERR_HEADER;
577 if ((err = y4m_snprint_xtags(s + n, sizeof(s) - n - 1, &(i->x_tags)))
578 != Y4M_OK)
579 return err;
580 /* non-zero on error */
581 return (y4m_write(fd, s, strlen(s)) ? Y4M_ERR_SYSTEM : Y4M_OK);
583 #endif
587 /*************************************************************************
589 * Read/Write entire frame
591 *************************************************************************/
593 int y4m_read_frame(stream_t *s, y4m_stream_info_t *si,
594 y4m_frame_info_t *fi, unsigned char *yuv[3])
596 int err;
597 int w = si->width;
598 int h = si->height;
600 /* Read frame header */
601 if ((err = y4m_read_frame_header(s, fi)) != Y4M_OK) return err;
602 /* Read luminance scanlines */
603 if (y4m_read(s, yuv[0], w*h)) return Y4M_ERR_SYSTEM;
604 /* Read chrominance scanlines */
605 if (y4m_read(s, yuv[1], w*h/4)) return Y4M_ERR_SYSTEM;
606 if (y4m_read(s, yuv[2], w*h/4)) return Y4M_ERR_SYSTEM;
608 return Y4M_OK;
613 #if 0
614 int y4m_write_frame(int fd, y4m_stream_info_t *si,
615 y4m_frame_info_t *fi, unsigned char *yuv[3])
617 int err;
618 int w = si->width;
619 int h = si->height;
621 /* Write frame header */
622 if ((err = y4m_write_frame_header(fd, fi)) != Y4M_OK) return err;
623 /* Write luminance,chrominance scanlines */
624 if (y4m_write(fd, yuv[0], w*h) ||
625 y4m_write(fd, yuv[1], w*h/4) ||
626 y4m_write(fd, yuv[2], w*h/4))
627 return Y4M_ERR_SYSTEM;
628 return Y4M_OK;
630 #endif
633 /*************************************************************************
635 * Read/Write entire frame, (de)interleaved (to)from two separate fields
637 *************************************************************************/
639 #if 0
640 int y4m_read_fields(int fd, y4m_stream_info_t *si, y4m_frame_info_t *fi,
641 unsigned char *upper_field[3],
642 unsigned char *lower_field[3])
644 int i, y, err;
645 int width = si->width;
646 int height = si->height;
648 /* Read frame header */
649 if ((err = y4m_read_frame_header(fd, fi)) != Y4M_OK) return err;
650 /* Read Y', Cb, and Cr planes */
651 for (i = 0; i < 3; i++) {
652 unsigned char *srctop = upper_field[i];
653 unsigned char *srcbot = lower_field[i];
654 /* alternately write one line from each */
655 for (y = 0; y < height; y += 2) {
656 if (y4m_read(fd, srctop, width)) return Y4M_ERR_SYSTEM;
657 srctop += width;
658 if (y4m_read(fd, srcbot, width)) return Y4M_ERR_SYSTEM;
659 srcbot += width;
661 /* for chroma, width/height are half as big */
662 if (i == 0) {
663 width /= 2;
664 height /= 2;
667 return Y4M_OK;
672 int y4m_write_fields(int fd, y4m_stream_info_t *si, y4m_frame_info_t *fi,
673 unsigned char *upper_field[3],
674 unsigned char *lower_field[3])
676 int i, y, err;
677 int width = si->width;
678 int height = si->height;
680 /* Write frame header */
681 if ((err = y4m_write_frame_header(fd, fi)) != Y4M_OK) return err;
682 /* Write Y', Cb, and Cr planes */
683 for (i = 0; i < 3; i++) {
684 unsigned char *srctop = upper_field[i];
685 unsigned char *srcbot = lower_field[i];
686 /* alternately write one line from each */
687 for (y = 0; y < height; y += 2) {
688 if (y4m_write(fd, srctop, width)) return Y4M_ERR_SYSTEM;
689 srctop += width;
690 if (y4m_write(fd, srcbot, width)) return Y4M_ERR_SYSTEM;
691 srcbot += width;
693 /* for chroma, width/height are half as big */
694 if (i == 0) {
695 width /= 2;
696 height /= 2;
699 return Y4M_OK;
701 #endif
704 /*************************************************************************
706 * Handy logging of stream info
708 *************************************************************************/
710 void y4m_log_stream_info(const char *prefix, y4m_stream_info_t *i)
712 char s[256];
714 snprintf(s, sizeof(s), " frame size: ");
715 if (i->width == Y4M_UNKNOWN)
716 snprintf(s+strlen(s), sizeof(s)-strlen(s), "(?)x");
717 else
718 snprintf(s+strlen(s), sizeof(s)-strlen(s), "%dx", i->width);
719 if (i->height == Y4M_UNKNOWN)
720 snprintf(s+strlen(s), sizeof(s)-strlen(s), "(?) pixels ");
721 else
722 snprintf(s+strlen(s), sizeof(s)-strlen(s), "%d pixels ", i->height);
723 if (i->framelength == Y4M_UNKNOWN)
724 snprintf(s+strlen(s), sizeof(s)-strlen(s), "(? bytes)");
725 else
726 snprintf(s+strlen(s), sizeof(s)-strlen(s), "(%d bytes)", i->framelength);
727 mp_msg(MSGT_DEMUX, MSGL_V, "%s%s\n", prefix, s);
728 if ((i->framerate.n == 0) && (i->framerate.d == 0))
729 mp_msg(MSGT_DEMUX, MSGL_V, "%s frame rate: ??? fps\n", prefix);
730 else
731 mp_msg(MSGT_DEMUX, MSGL_V, "%s frame rate: %d/%d fps (~%f)\n", prefix,
732 i->framerate.n, i->framerate.d,
733 (double) i->framerate.n / (double) i->framerate.d);
734 mp_msg(MSGT_DEMUX, MSGL_V, "%s interlace: %s\n", prefix,
735 (i->interlace == Y4M_ILACE_NONE) ? "none/progressive" :
736 (i->interlace == Y4M_ILACE_TOP_FIRST) ? "top-field-first" :
737 (i->interlace == Y4M_ILACE_BOTTOM_FIRST) ? "bottom-field-first" :
738 "anyone's guess");
739 if ((i->sampleaspect.n == 0) && (i->sampleaspect.d == 0))
740 mp_msg(MSGT_DEMUX, MSGL_V, "%ssample aspect ratio: ?:?\n", prefix);
741 else
742 mp_msg(MSGT_DEMUX, MSGL_V, "%ssample aspect ratio: %d:%d\n", prefix,
743 i->sampleaspect.n, i->sampleaspect.d);
747 /*************************************************************************
749 * Convert error code to string
751 *************************************************************************/
753 const char *y4m_strerr(int err)
755 switch (err) {
756 case Y4M_OK: return "no error";
757 case Y4M_ERR_RANGE: return "parameter out of range";
758 case Y4M_ERR_SYSTEM: return "stream ended unexpectedly (failed read/write)";
759 case Y4M_ERR_HEADER: return "bad stream or frame header";
760 case Y4M_ERR_BADTAG: return "unknown header tag";
761 case Y4M_ERR_MAGIC: return "bad header magic";
762 case Y4M_ERR_XXTAGS: return "too many xtags";
763 case Y4M_ERR_EOF: return "end-of-file";
764 default:
765 return "unknown error code";