if (!dv->ring) {
if (dv->ring == MAP_FAILED) {
static int dv1394_read_header(AVFormatContext * context, AVFormatParameters * ap){    struct dv1394_data *dv = context->priv_data;    AVStream *vst, *ast;    const char *video_device;    vst = av_new_stream(context, 0);    if (!vst)        return -ENOMEM;    ast = av_new_stream(context, 1);    if (!ast) {        av_free(vst);        return -ENOMEM;    }    if (ap->standard && !strcasecmp(ap->standard, "pal"))	dv->format = DV1394_PAL;    else	dv->format = DV1394_NTSC;    if (ap->channel)        dv->channel = ap->channel;    else        dv->channel = DV1394_DEFAULT_CHANNEL;    dv->width = DV1394_WIDTH;    if (dv->format == DV1394_NTSC) {	dv->height = DV1394_NTSC_HEIGHT;        dv->frame_size = DV1394_NTSC_FRAME_SIZE;        dv->frame_rate = 30;    } else {	dv->height = DV1394_PAL_HEIGHT;        dv->frame_size = DV1394_PAL_FRAME_SIZE;        dv->frame_rate = 25;    }    /* Open and initialize DV1394 device */    video_device = ap->device;    if (!video_device)        video_device = "/dev/dv1394/0";    dv->fd = open(video_device, O_RDONLY);    if (dv->fd < 0) {        perror("Failed to open DV interface");        goto failed;    }    if (dv1394_reset(dv) < 0) {        perror("Failed to initialize DV interface");        goto failed;    }    dv->ring = mmap(NULL, DV1394_NTSC_FRAME_SIZE * DV1394_RING_FRAMES,                    PROT_READ, MAP_PRIVATE, dv->fd, 0);    if (!dv->ring) {        perror("Failed to mmap DV ring buffer");        goto failed;    }    dv->stream = 0;    vst->codec.codec_type = CODEC_TYPE_VIDEO;    vst->codec.codec_id   = CODEC_ID_DVVIDEO;    vst->codec.width      = dv->width;    vst->codec.height     = dv->height;    vst->codec.frame_rate = dv->frame_rate;    vst->codec.frame_rate_base = 1;    vst->codec.bit_rate   = 25000000;  /* Consumer DV is 25Mbps */    ast->codec.codec_type = CODEC_TYPE_AUDIO;    ast->codec.codec_id   = CODEC_ID_DVAUDIO;    ast->codec.channels   = 2;    ast->codec.sample_rate= 48000;    av_set_pts_info(context, 48, 1, 1000000);    if (dv1394_start(dv) < 0)        goto failed;    return 0;failed:    close(dv->fd);    av_free(vst);    av_free(ast);    return -EIO;}