diff --git a/libavcodec/Makefile b/libavcodec/Makefile index 36e07a9fc1..2264e86b7d 100644 --- a/libavcodec/Makefile +++ b/libavcodec/Makefile @@ -616,6 +616,8 @@ OBJS-$(CONFIG_MPEGVIDEO_PARSER) += mpegvideo_parser.o \ mpeg12.o mpeg12data.o \ mpegvideo.o error_resilience.o OBJS-$(CONFIG_PNM_PARSER) += pnm_parser.o pnm.o +OBJS-$(CONFIG_RV30_PARSER) += rv34_parser.o +OBJS-$(CONFIG_RV40_PARSER) += rv34_parser.o OBJS-$(CONFIG_VC1_PARSER) += vc1_parser.o vc1.o vc1data.o \ msmpeg4.o msmpeg4data.o mpeg4video.o \ h263.o mpegvideo.o error_resilience.o diff --git a/libavcodec/allcodecs.c b/libavcodec/allcodecs.c index dcef0d6d94..7ba945c3d4 100644 --- a/libavcodec/allcodecs.c +++ b/libavcodec/allcodecs.c @@ -396,6 +396,8 @@ void avcodec_register_all(void) REGISTER_PARSER (MPEGAUDIO, mpegaudio); REGISTER_PARSER (MPEGVIDEO, mpegvideo); REGISTER_PARSER (PNM, pnm); + REGISTER_PARSER (RV30, rv30); + REGISTER_PARSER (RV40, rv40); REGISTER_PARSER (VC1, vc1); REGISTER_PARSER (VP3, vp3); REGISTER_PARSER (VP8, vp8); diff --git a/libavcodec/rv34_parser.c b/libavcodec/rv34_parser.c new file mode 100644 index 0000000000..c2563a5fdc --- /dev/null +++ b/libavcodec/rv34_parser.c @@ -0,0 +1,97 @@ +/* + * RV30/40 parser + * Copyright (c) 2011 Konstantin Shishkov + * + * This file is part of Libav. + * + * Libav is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * Libav is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with Libav; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +/** + * @file + * RV30/40 parser + */ + +#include "parser.h" +#include "libavutil/intreadwrite.h" + +typedef struct { + ParseContext pc; + int64_t key_dts; + int key_pts; +} RV34ParseContext; + +static const int rv_to_av_frame_type[4] = { + AV_PICTURE_TYPE_I, AV_PICTURE_TYPE_I, AV_PICTURE_TYPE_P, AV_PICTURE_TYPE_B, +}; + +static int rv34_parse(AVCodecParserContext *s, + AVCodecContext *avctx, + const uint8_t **poutbuf, int *poutbuf_size, + const uint8_t *buf, int buf_size) +{ + RV34ParseContext *pc = s->priv_data; + int off; + int type, pts, hdr; + + if (buf_size < 13 + *buf * 8) { + *poutbuf = buf; + *poutbuf_size = buf_size; + return buf_size; + } + + off = AV_RL32(buf + 5); + hdr = AV_RB32(buf + 9 + *buf * 8); + if (avctx->codec_id == CODEC_ID_RV30) { + type = (hdr >> 27) & 3; + pts = (hdr >> 7) & 0x1FFF; + } else { + type = (hdr >> 29) & 3; + pts = (hdr >> 6) & 0x1FFF; + } + + if (type != 3 && s->pts != AV_NOPTS_VALUE) { + pc->key_dts = s->pts; + pc->key_pts = pts; + } else { + if (type != 3) + s->pts = pc->key_dts + ((pts - pc->key_pts) & 0x1FFF); + else + s->pts = pc->key_dts - ((pc->key_pts - pts) & 0x1FFF); + } + s->pict_type = rv_to_av_frame_type[type]; + + *poutbuf = buf; + *poutbuf_size = buf_size; + return buf_size; +} + +#ifdef CONFIG_RV30_PARSER +AVCodecParser ff_rv30_parser = { + { CODEC_ID_RV30 }, + sizeof(RV34ParseContext), + NULL, + rv34_parse, +}; +#endif + +#ifdef CONFIG_RV40_PARSER +AVCodecParser ff_rv40_parser = { + { CODEC_ID_RV40 }, + sizeof(RV34ParseContext), + NULL, + rv34_parse, +}; +#endif diff --git a/libavformat/rmdec.c b/libavformat/rmdec.c index 5ee75b53b9..cf5c46a095 100644 --- a/libavformat/rmdec.c +++ b/libavformat/rmdec.c @@ -298,6 +298,7 @@ ff_rm_read_mdpr_codecdata (AVFormatContext *s, AVIOContext *pb, st->codec->time_base.num= 1; fps= avio_rb16(pb); st->codec->codec_type = AVMEDIA_TYPE_VIDEO; + st->need_parsing = AVSTREAM_PARSE_TIMESTAMPS; avio_rb32(pb); avio_skip(pb, 2); avio_rb16(pb); diff --git a/tests/ref/fate/real-rv40 b/tests/ref/fate/real-rv40 index 990a530436..22cc731c89 100644 --- a/tests/ref/fate/real-rv40 +++ b/tests/ref/fate/real-rv40 @@ -16,106 +16,105 @@ 0, 112500, 276480, 0x5f7a0d4f 0, 120000, 276480, 0x5f7a0d4f 0, 127500, 276480, 0x5f7a0d4f -0, 135000, 276480, 0x75641594 -0, 142500, 276480, 0x32ee3526 -0, 150000, 276480, 0x5ce39368 -0, 157500, 276480, 0x4ec1e418 -0, 165000, 276480, 0x85cbc3b5 -0, 172500, 276480, 0x377c7b46 -0, 180000, 276480, 0x756a4a2e -0, 187500, 276480, 0xcb379547 -0, 195000, 276480, 0x99c085be -0, 202500, 276480, 0xe479ffed -0, 210000, 276480, 0x1e4fae19 -0, 217500, 276480, 0x776412ef -0, 225000, 276480, 0x58ce0f38 -0, 232500, 276480, 0x5ab69b27 -0, 240000, 276480, 0xc3db9706 -0, 247500, 276480, 0xc9c57884 -0, 255000, 276480, 0x000b5269 -0, 262500, 276480, 0x27ff7a5d -0, 270000, 276480, 0x70647530 -0, 277500, 276480, 0x97612c4b -0, 285000, 276480, 0xdf4e04d7 -0, 292500, 276480, 0xbd98f57c -0, 300000, 276480, 0x5163b29b -0, 307500, 276480, 0x99170e64 -0, 315000, 276480, 0x8a4e991f -0, 322500, 276480, 0x6a45425f -0, 330000, 276480, 0x7bf6b1ef -0, 337500, 276480, 0x6de1e34b -0, 345000, 276480, 0xdcaaa99a -0, 352500, 276480, 0xd1e98808 -0, 360000, 276480, 0x6e2d524e -0, 367500, 276480, 0x22c50a3d -0, 375000, 276480, 0x62b76407 -0, 382500, 276480, 0x51e9b3eb -0, 390000, 276480, 0x441f7afd -0, 397500, 276480, 0xfb01efc6 -0, 405000, 276480, 0x294bb441 -0, 412500, 276480, 0xe04ac45e -0, 420000, 276480, 0x58f275ea -0, 427500, 276480, 0xf0b3b71b -0, 435000, 276480, 0x674e34e4 -0, 442500, 276480, 0x41dda2d9 -0, 450000, 276480, 0xf46ba7fb -0, 457500, 276480, 0x28b54815 -0, 465000, 276480, 0xaf2b5d89 -0, 472500, 276480, 0x8facba58 -0, 480000, 276480, 0x28a63236 -0, 487500, 276480, 0x1ad43fd7 -0, 495000, 276480, 0x71507bd2 -0, 502500, 276480, 0x35626022 -0, 510000, 276480, 0x7c1139b3 -0, 517500, 276480, 0x7fd73a99 -0, 525000, 276480, 0xb52e1aa2 -0, 532500, 276480, 0xd6f82cae -0, 540000, 276480, 0xf88f75d4 -0, 547500, 276480, 0x04a8e3ee -0, 555000, 276480, 0xa29f5b01 -0, 562500, 276480, 0x754ceaf5 -0, 570000, 276480, 0x5a38b4af -0, 577500, 276480, 0xfcebc261 -0, 585000, 276480, 0x3d3ca985 -0, 592500, 276480, 0x94a03c75 -0, 600000, 276480, 0x2f98911c -0, 607500, 276480, 0x923b9937 -0, 615000, 276480, 0xefab7ffd -0, 622500, 276480, 0x6b9fbc80 -0, 630000, 276480, 0xe4bdbd1e -0, 637500, 276480, 0x225a56c0 -0, 645000, 276480, 0xf58b1b7c -0, 652500, 276480, 0xbaffcdcc -0, 660000, 276480, 0xeb6eb88f -0, 667500, 276480, 0xdb753d35 -0, 675000, 276480, 0xea80a82e -0, 682500, 276480, 0x2aae902a -0, 690000, 276480, 0x9b9ee961 -0, 697500, 276480, 0xaa12b6fd -0, 705000, 276480, 0x50c31e73 -0, 712500, 276480, 0xdd9fb89f -0, 720000, 276480, 0xaf82399a -0, 727500, 276480, 0x7ce5f23c -0, 735000, 276480, 0x5aaa7519 -0, 742500, 276480, 0xe45a5599 -0, 750000, 276480, 0x704411fb -0, 757500, 276480, 0x9d7430a1 -0, 765000, 276480, 0x2c230702 -0, 772500, 276480, 0x4a4f76cd -0, 780000, 276480, 0x27f54854 -0, 787500, 276480, 0x694d76e3 -0, 795000, 276480, 0x525463e2 -0, 802500, 276480, 0x819898f9 -0, 810000, 276480, 0xeeed00fc -0, 817500, 276480, 0xb6f99ee3 -0, 825000, 276480, 0xefc83107 -0, 832500, 276480, 0xbb22e024 -0, 840000, 276480, 0x300f922a -0, 847500, 276480, 0x826fc3bd -0, 855000, 276480, 0x679a53f8 -0, 862500, 276480, 0x976c9e93 -0, 870000, 276480, 0xb194656e -0, 877500, 276480, 0xf002c5ca -0, 885000, 276480, 0xb243dda5 -0, 892500, 276480, 0x1700efbb -0, 900000, 276480, 0x8f316c66 +0, 135000, 276480, 0x32ee3526 +0, 142500, 276480, 0x7ca9658e +0, 150000, 276480, 0x4ec1e418 +0, 157500, 276480, 0xa9f1506f +0, 165000, 276480, 0x377c7b46 +0, 172500, 276480, 0xe1de7f0a +0, 180000, 276480, 0xcb379547 +0, 187500, 276480, 0x8e12331c +0, 195000, 276480, 0xe479ffed +0, 202500, 276480, 0xac7672dd +0, 210000, 276480, 0x776412ef +0, 217500, 276480, 0x1cd1ab29 +0, 225000, 276480, 0x5ab69b27 +0, 232500, 276480, 0x9eca3f11 +0, 240000, 276480, 0xc9c57884 +0, 247500, 276480, 0xdc07f3c9 +0, 255000, 276480, 0x27ff7a5d +0, 262500, 276480, 0x18d4b27d +0, 270000, 276480, 0x97612c4b +0, 277500, 276480, 0x4ec4d57f +0, 285000, 276480, 0xbd98f57c +0, 292500, 276480, 0xa5d670ec +0, 300000, 276480, 0x99170e64 +0, 307500, 276480, 0x7a4f2561 +0, 315000, 276480, 0x6a45425f +0, 322500, 276480, 0xd75482c6 +0, 330000, 276480, 0x6de1e34b +0, 337500, 276480, 0xf964e18e +0, 345000, 276480, 0xd1e98808 +0, 352500, 276480, 0x0cf65540 +0, 360000, 276480, 0x22c50a3d +0, 367500, 276480, 0xf4b1c461 +0, 375000, 276480, 0x51e9b3eb +0, 382500, 276480, 0x6dd14ca6 +0, 390000, 276480, 0xfb01efc6 +0, 397500, 276480, 0x5ac8e06f +0, 405000, 276480, 0xe04ac45e +0, 412500, 276480, 0xf688a3ed +0, 420000, 276480, 0xf0b3b71b +0, 427500, 276480, 0x01840548 +0, 435000, 276480, 0x41dda2d9 +0, 442500, 276480, 0x9b209f41 +0, 450000, 276480, 0x28b54815 +0, 457500, 276480, 0x34484aff +0, 465000, 276480, 0x8facba58 +0, 472500, 276480, 0x02162c7c +0, 480000, 276480, 0x1ad43fd7 +0, 487500, 276480, 0x2b8a89c5 +0, 495000, 276480, 0x35626022 +0, 502500, 276480, 0xce5af1ec +0, 510000, 276480, 0x7fd73a99 +0, 517500, 276480, 0xcb60725a +0, 525000, 276480, 0xd6f82cae +0, 532500, 276480, 0xfa88a483 +0, 540000, 276480, 0x04a8e3ee +0, 547500, 276480, 0x0b41f0d7 +0, 555000, 276480, 0x754ceaf5 +0, 562500, 276480, 0xde084059 +0, 570000, 276480, 0xfcebc261 +0, 577500, 276480, 0x046394ae +0, 585000, 276480, 0x94a03c75 +0, 592500, 276480, 0x6a841f41 +0, 600000, 276480, 0x923b9937 +0, 607500, 276480, 0xee82d657 +0, 615000, 276480, 0x6b9fbc80 +0, 622500, 276480, 0x6d4b49d7 +0, 630000, 276480, 0x225a56c0 +0, 637500, 276480, 0xff4e1a8c +0, 645000, 276480, 0xbaffcdcc +0, 652500, 276480, 0x3d861ae6 +0, 660000, 276480, 0xdb753d35 +0, 667500, 276480, 0xb24c8016 +0, 675000, 276480, 0x2aae902a +0, 682500, 276480, 0x5c6e97a9 +0, 690000, 276480, 0xaa12b6fd +0, 697500, 276480, 0xbf09053c +0, 705000, 276480, 0xdd9fb89f +0, 712500, 276480, 0x0b752d28 +0, 720000, 276480, 0x7ce5f23c +0, 727500, 276480, 0x55dadd30 +0, 735000, 276480, 0xe45a5599 +0, 742500, 276480, 0x2f447fd3 +0, 750000, 276480, 0x9d7430a1 +0, 757500, 276480, 0x51cb657c +0, 765000, 276480, 0x4a4f76cd +0, 772500, 276480, 0x87160f99 +0, 780000, 276480, 0x694d76e3 +0, 787500, 276480, 0x50742e1b +0, 795000, 276480, 0x819898f9 +0, 802500, 276480, 0x35c46927 +0, 810000, 276480, 0xb6f99ee3 +0, 817500, 276480, 0xde97d9fd +0, 825000, 276480, 0xbb22e024 +0, 832500, 276480, 0xbe1fbb19 +0, 840000, 276480, 0x826fc3bd +0, 847500, 276480, 0x5497097b +0, 855000, 276480, 0x976c9e93 +0, 862500, 276480, 0xdc2d7c6c +0, 870000, 276480, 0xf002c5ca +0, 877500, 276480, 0xf62d8581 +0, 885000, 276480, 0x1700efbb +0, 892500, 276480, 0x8f316c66 diff --git a/tests/ref/fate/rv30 b/tests/ref/fate/rv30 index 867151bd66..8777367c8e 100644 --- a/tests/ref/fate/rv30 +++ b/tests/ref/fate/rv30 @@ -2,45 +2,44 @@ 0, 7500, 126720, 0xa416ece5 0, 15000, 126720, 0xa416ece5 0, 22500, 126720, 0x259af497 -0, 30000, 126720, 0x5e6ff4d7 -0, 37500, 126720, 0xeb6fb8d7 +0, 30000, 126720, 0x763ab817 +0, 37500, 126720, 0xda71b917 0, 45000, 126720, 0xbb1abbb7 -0, 52500, 126720, 0x273fbc37 -0, 60000, 126720, 0x7fa3ae27 -0, 67500, 126720, 0x722e99f7 -0, 75000, 126720, 0x29d6a887 +0, 52500, 126720, 0x16eebbd7 +0, 60000, 126720, 0x722e99f7 +0, 67500, 126720, 0x07beba77 +0, 75000, 126720, 0x9ca7aac7 0, 82500, 126720, 0xd115a757 -0, 90000, 126720, 0x6ddaef32 -0, 97500, 126720, 0x04e7897c +0, 90000, 126720, 0xac6c071b +0, 97500, 126720, 0x5eee050f 0, 105000, 126720, 0x68cfda2b -0, 112500, 126720, 0xe572dfc9 -0, 120000, 126720, 0xbc3cc34f -0, 127500, 126720, 0xcf8cb0e2 -0, 135000, 126720, 0x75ae61b6 +0, 112500, 126720, 0x582fb176 +0, 120000, 126720, 0xcf8cb0e2 +0, 127500, 126720, 0xc6e10f9f +0, 135000, 126720, 0x85597543 0, 142500, 126720, 0x554fe3e4 -0, 150000, 126720, 0x72ecea95 -0, 157500, 126720, 0x5d00b5fe +0, 150000, 126720, 0x9bf6a605 +0, 157500, 126720, 0x93f7b040 0, 165000, 126720, 0xe39bba0d -0, 172500, 126720, 0x9c21bad8 -0, 180000, 126720, 0x72f2a47d -0, 187500, 126720, 0x4f639ebe -0, 195000, 126720, 0x534a10cc +0, 172500, 126720, 0xa567f25b +0, 180000, 126720, 0x4f639ebe +0, 187500, 126720, 0x6cf87d39 +0, 195000, 126720, 0xfdca11d3 0, 202500, 126720, 0x5fd753d8 -0, 210000, 126720, 0x0c735615 -0, 217500, 126720, 0x0eaf0c1b +0, 210000, 126720, 0xeaf3dd0b +0, 217500, 126720, 0xce5e6794 0, 225000, 126720, 0x14cf7974 -0, 232500, 126720, 0x1c2a513d -0, 240000, 126720, 0xbc513f2a -0, 247500, 126720, 0xbc303fae -0, 255000, 126720, 0xd9f67585 +0, 232500, 126720, 0xa3f515ab +0, 240000, 126720, 0xbc303fae +0, 247500, 126720, 0x0a22cc69 +0, 255000, 126720, 0xf92b2a25 0, 262500, 126720, 0x3378251f -0, 270000, 126720, 0xb3ed5911 -0, 277500, 126720, 0xc15a3577 +0, 270000, 126720, 0x8da30275 +0, 277500, 126720, 0xf2942f53 0, 285000, 126720, 0x0a24f256 -0, 292500, 126720, 0xfab9c45d -0, 300000, 126720, 0x45464610 -0, 307500, 126720, 0xfe2e057d -0, 315000, 126720, 0x23efdc35 +0, 292500, 126720, 0x10e939ce +0, 300000, 126720, 0xfe2e057d +0, 307500, 126720, 0x5284da7b +0, 315000, 126720, 0xc9e92bf1 0, 322500, 126720, 0x4d888b2e -0, 330000, 126720, 0xdd0d74df -0, 337500, 126720, 0x08382b8e +0, 330000, 126720, 0x08382b8e