*/
#include "libavutil/channel_layout.h"
+#include "libavutil/imgutils.h"
#include "libavutil/intreadwrite.h"
#include "libavutil/intfloat.h"
#include "avformat.h"
{ AV_CODEC_ID_NONE, 0 },
};
-typedef struct {
+typedef struct NUVContext {
int v_id;
int a_id;
int rtjpg_video;
* @param vst video stream of which to change parameters
* @param ast video stream of which to change parameters
* @param myth set if this is a MythTVVideo format file
- * @return 1 if all required codec data was found
+ * @return 0 or AVERROR code
*/
static int get_codec_data(AVIOContext *pb, AVStream *vst,
AVStream *ast, int myth)
avio_skip(pb, 6);
size = PKTSIZE(avio_rl32(pb));
if (vst && subtype == 'R') {
+ if (vst->codec->extradata) {
+ av_freep(&vst->codec->extradata);
+ vst->codec->extradata_size = 0;
+ }
+ vst->codec->extradata = av_malloc(size);
+ if (!vst->codec->extradata)
+ return AVERROR(ENOMEM);
vst->codec->extradata_size = size;
- vst->codec->extradata = av_malloc(size);
avio_read(pb, vst->codec->extradata, size);
size = 0;
if (!myth)
- return 1;
+ return 0;
}
break;
case NUV_MYTHEXT:
size -= 6 * 4;
avio_skip(pb, size);
- return 1;
+ return 0;
case NUV_SEEKP:
size = 11;
break;
AVIOContext *pb = s->pb;
char id_string[12];
double aspect, fps;
- int is_mythtv, width, height, v_packs, a_packs;
- int stream_nr = 0;
+ int is_mythtv, width, height, v_packs, a_packs, ret;
AVStream *vst = NULL, *ast = NULL;
avio_read(pb, id_string, 12);
avio_rl32(pb); // keyframe distance (?)
if (v_packs) {
- ctx->v_id = stream_nr++;
- vst = avformat_new_stream(s, NULL);
+ vst = avformat_new_stream(s, NULL);
if (!vst)
return AVERROR(ENOMEM);
+ ctx->v_id = vst->index;
+
+ ret = av_image_check_size(width, height, 0, ctx);
+ if (ret < 0)
+ return ret;
+
vst->codec->codec_type = AVMEDIA_TYPE_VIDEO;
vst->codec->codec_id = AV_CODEC_ID_NUV;
vst->codec->width = width;
vst->codec->bits_per_coded_sample = 10;
vst->sample_aspect_ratio = av_d2q(aspect * height / width,
10000);
-#if FF_API_R_FRAME_RATE
- vst->r_frame_rate =
-#endif
vst->avg_frame_rate = av_d2q(fps, 60000);
avpriv_set_pts_info(vst, 32, 1, 1000);
} else
ctx->v_id = -1;
if (a_packs) {
- ctx->a_id = stream_nr++;
- ast = avformat_new_stream(s, NULL);
+ ast = avformat_new_stream(s, NULL);
if (!ast)
return AVERROR(ENOMEM);
+ ctx->a_id = ast->index;
+
ast->codec->codec_type = AVMEDIA_TYPE_AUDIO;
ast->codec->codec_id = AV_CODEC_ID_PCM_S16LE;
ast->codec->channels = 2;
} else
ctx->a_id = -1;
- get_codec_data(pb, vst, ast, is_mythtv);
+ if ((ret = get_codec_data(pb, vst, ast, is_mythtv)) < 0)
+ return ret;
+
ctx->rtjpg_video = vst && vst->codec->codec_id == AV_CODEC_ID_NUV;
return 0;