예제 #1
0
static int framecrc_write_packet(struct AVFormatContext *s, AVPacket *pkt)
{
    uint32_t crc = av_adler32_update(0, pkt->data, pkt->size);
    char buf[256];

    snprintf(buf, sizeof(buf), "%d, %10"PRId64", %10"PRId64", %8d, %8d, 0x%08x",
             pkt->stream_index, pkt->dts, pkt->pts, pkt->duration, pkt->size, crc);
    if (pkt->flags != AV_PKT_FLAG_KEY)
        av_strlcatf(buf, sizeof(buf), ", F=0x%0X", pkt->flags);
    if (pkt->side_data_elems) {
        int i, j;
        av_strlcatf(buf, sizeof(buf), ", S=%d", pkt->side_data_elems);

        for (i=0; i<pkt->side_data_elems; i++) {
            uint32_t side_data_crc = 0;
            if (HAVE_BIGENDIAN && AV_PKT_DATA_PALETTE == pkt->side_data[i].type) {
                for (j=0; j<pkt->side_data[i].size; j++) {
                    side_data_crc = av_adler32_update(side_data_crc,
                                                      pkt->side_data[i].data + (j^3),
                                                      1);
                }
            } else {
                side_data_crc = av_adler32_update(0,
                                                  pkt->side_data[i].data,
                                                  pkt->side_data[i].size);
            }
            av_strlcatf(buf, sizeof(buf), ", %8d, 0x%08x", pkt->side_data[i].size, side_data_crc);
        }
    }
    av_strlcatf(buf, sizeof(buf), "\n");
    avio_write(s->pb, buf, strlen(buf));
    return 0;
}
예제 #2
0
static void end_frame(AVFilterLink *inlink)
{
    AVFilterContext *ctx = inlink->dst;
    ShowInfoContext *showinfo = ctx->priv;
    AVFilterBufferRef *picref = inlink->cur_buf;
    uint32_t plane_crc[4], crc = 0;
    int plane;

    for (plane = 0; plane < 4; plane++) {
        size_t linesize = av_image_get_linesize(picref->format, picref->video->w, plane);
        plane_crc[plane] = av_adler32_update(0  , picref->data[plane], linesize);
        crc              = av_adler32_update(crc, picref->data[plane], linesize);
    }

    av_log(ctx, AV_LOG_INFO,
           "n:%d pts:%"PRId64" pts_time:%f pos:%"PRId64" "
           "fmt:%s sar:%d/%d s:%dx%d i:%c iskey:%d type:%c "
           "crc:%u plane_crc:[%u %u %u %u]\n",
           showinfo->frame,
           picref->pts, picref ->pts * av_q2d(inlink->time_base), picref->pos,
           av_pix_fmt_descriptors[picref->format].name,
           picref->video->sample_aspect_ratio.num, picref->video->sample_aspect_ratio.den,
           picref->video->w, picref->video->h,
           !picref->video->interlaced     ? 'P' :         /* Progressive  */
           picref->video->top_field_first ? 'T' : 'B',    /* Top / Bottom */
           picref->video->key_frame,
           av_get_picture_type_char(picref->video->pict_type),
           crc, plane_crc[0], plane_crc[1], plane_crc[2], plane_crc[3]);

    showinfo->frame++;
    avfilter_end_frame(inlink->dst->outputs[0]);
}
예제 #3
0
static void video_frame_cksum(AVBPrint *bp, AVFrame *frame)
{
    const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(frame->format);
    int i, y;
    uint8_t *data;
    int linesize[5] = { 0 };

    av_bprintf(bp, ", %d x %d", frame->width, frame->height);
    if (!desc) {
        av_bprintf(bp, ", unknown");
        return;
    }
    if (av_image_fill_linesizes(linesize, frame->format, frame->width) < 0)
        return;
    av_bprintf(bp, ", %s", desc->name);
    for (i = 0; linesize[i]; i++) {
        unsigned cksum = 0;
        int h = frame->height;
        if ((i == 1 || i == 2) && desc->nb_components >= 3)
            h = AV_CEIL_RSHIFT(h, desc->log2_chroma_h);
        data = frame->data[i];
        for (y = 0; y < h; y++) {
            cksum = av_adler32_update(cksum, data, linesize[i]);
            data += frame->linesize[i];
        }
        av_bprintf(bp, ", 0x%08x", cksum);
    }
}
예제 #4
0
static int filter_frame(AVFilterLink *inlink, AVFrame *buf)
{
    AVFilterContext *ctx = inlink->dst;
    AShowInfoContext *s  = ctx->priv;
    char chlayout_str[128];
    uint32_t checksum = 0;
    int channels    = av_get_channel_layout_nb_channels(buf->channel_layout);
    int planar      = av_sample_fmt_is_planar(buf->format);
    int block_align = av_get_bytes_per_sample(buf->format) * (planar ? 1 : channels);
    int data_size   = buf->nb_samples * block_align;
    int planes      = planar ? channels : 1;
    int i;
    void *tmp_ptr = av_realloc(s->plane_checksums, channels * sizeof(*s->plane_checksums));

    if (!tmp_ptr)
        return AVERROR(ENOMEM);
    s->plane_checksums = tmp_ptr;

    for (i = 0; i < planes; i++) {
        uint8_t *data = buf->extended_data[i];

        s->plane_checksums[i] = av_adler32_update(0, data, data_size);
        checksum = i ? av_adler32_update(checksum, data, data_size) :
                       s->plane_checksums[0];
    }

    av_get_channel_layout_string(chlayout_str, sizeof(chlayout_str), -1,
                                 buf->channel_layout);

    av_log(ctx, AV_LOG_INFO,
           "n:%"PRId64" pts:%s pts_time:%s pos:%"PRId64" "
           "fmt:%s channels:%d chlayout:%s rate:%d nb_samples:%d "
           "checksum:%08X ",
           inlink->frame_count,
           av_ts2str(buf->pts), av_ts2timestr(buf->pts, &inlink->time_base),
           av_frame_get_pkt_pos(buf),
           av_get_sample_fmt_name(buf->format), av_frame_get_channels(buf), chlayout_str,
           buf->sample_rate, buf->nb_samples,
           checksum);

    av_log(ctx, AV_LOG_INFO, "plane_checksums: [ ");
    for (i = 0; i < planes; i++)
        av_log(ctx, AV_LOG_INFO, "%08X ", s->plane_checksums[i]);
    av_log(ctx, AV_LOG_INFO, "]\n");

    return ff_filter_frame(inlink->dst->outputs[0], buf);
}
예제 #5
0
static int end_frame(AVFilterLink *inlink)
{
    AVFilterContext *ctx = inlink->dst;
    ShowInfoContext *showinfo = ctx->priv;
    AVFilterBufferRef *picref = inlink->cur_buf;
    const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(inlink->format);
    uint32_t plane_checksum[4] = {0}, checksum = 0;
    int i, plane, vsub = desc->log2_chroma_h;

    for (plane = 0; picref->data[plane] && plane < 4; plane++) {
        int64_t linesize = av_image_get_linesize(picref->format, picref->video->w, plane);
        uint8_t *data = picref->data[plane];
        int h = plane == 1 || plane == 2 ? inlink->h >> vsub : inlink->h;

        if (linesize < 0)
            return linesize;

        for (i = 0; i < h; i++) {
            plane_checksum[plane] = av_adler32_update(plane_checksum[plane], data, linesize);
            checksum = av_adler32_update(checksum, data, linesize);
            data += picref->linesize[plane];
        }
    }

    av_log(ctx, AV_LOG_INFO,
           "n:%d pts:%s pts_time:%s pos:%"PRId64" "
           "fmt:%s sar:%d/%d s:%dx%d i:%c iskey:%d type:%c "
           "checksum:%08X plane_checksum:[%08X",
           showinfo->frame,
           av_ts2str(picref->pts), av_ts2timestr(picref->pts, &inlink->time_base), picref->pos,
           desc->name,
           picref->video->sample_aspect_ratio.num, picref->video->sample_aspect_ratio.den,
           picref->video->w, picref->video->h,
           !picref->video->interlaced     ? 'P' :         /* Progressive  */
           picref->video->top_field_first ? 'T' : 'B',    /* Top / Bottom */
           picref->video->key_frame,
           av_get_picture_type_char(picref->video->pict_type),
           checksum, plane_checksum[0]);

    for (plane = 1; picref->data[plane] && plane < 4; plane++)
        av_log(ctx, AV_LOG_INFO, " %08X", plane_checksum[plane]);
    av_log(ctx, AV_LOG_INFO, "]\n");

    showinfo->frame++;
    return ff_end_frame(inlink->dst->outputs[0]);
}
예제 #6
0
static void filter_samples(AVFilterLink *inlink, AVFilterBufferRef *samplesref)
{
    AVFilterContext *ctx = inlink->dst;
    ShowInfoContext *showinfo = ctx->priv;
    uint32_t plane_checksum[8] = {0}, checksum = 0;
    char chlayout_str[128];
    int plane;
    int linesize =
        samplesref->audio->nb_samples *
        av_get_bytes_per_sample(samplesref->format);
    if (!av_sample_fmt_is_planar(samplesref->format))
        linesize *= av_get_channel_layout_nb_channels(samplesref->audio->channel_layout);

    for (plane = 0; samplesref->data[plane] && plane < 8; plane++) {
        uint8_t *data = samplesref->data[plane];

        plane_checksum[plane] = av_adler32_update(plane_checksum[plane],
                                                  data, linesize);
        checksum = av_adler32_update(checksum, data, linesize);
    }

    av_get_channel_layout_string(chlayout_str, sizeof(chlayout_str), -1,
                                 samplesref->audio->channel_layout);

    av_log(ctx, AV_LOG_INFO,
           "n:%d pts:%s pts_time:%s pos:%"PRId64" "
           "fmt:%s chlayout:%s nb_samples:%d rate:%d "
           "checksum:%08X plane_checksum[%08X",
           showinfo->frame,
           av_ts2str(samplesref->pts), av_ts2timestr(samplesref->pts, &inlink->time_base),
           samplesref->pos,
           av_get_sample_fmt_name(samplesref->format),
           chlayout_str,
           samplesref->audio->nb_samples,
           samplesref->audio->sample_rate,
           checksum,
           plane_checksum[0]);

    for (plane = 1; samplesref->data[plane] && plane < 8; plane++)
        av_log(ctx, AV_LOG_INFO, " %08X", plane_checksum[plane]);
    av_log(ctx, AV_LOG_INFO, "]\n");

    showinfo->frame++;
    ff_filter_samples(inlink->dst->outputs[0], samplesref);
}
예제 #7
0
static int filter_frame(AVFilterLink *inlink, AVFrame *frame)
{
    AVFilterContext *ctx = inlink->dst;
    const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(inlink->format);
    uint32_t plane_checksum[4] = {0}, checksum = 0;
    int i, plane, vsub = desc->log2_chroma_h;

    for (plane = 0; plane < 4 && frame->data[plane] && frame->linesize[plane]; plane++) {
        int64_t linesize = av_image_get_linesize(frame->format, frame->width, plane);
        uint8_t *data = frame->data[plane];
        int h = plane == 1 || plane == 2 ? FF_CEIL_RSHIFT(inlink->h, vsub) : inlink->h;

        if (linesize < 0)
            return linesize;

        for (i = 0; i < h; i++) {
            plane_checksum[plane] = av_adler32_update(plane_checksum[plane], data, linesize);
            checksum = av_adler32_update(checksum, data, linesize);
            data += frame->linesize[plane];
        }
    }

    av_log(ctx, AV_LOG_INFO,
           "n:%"PRId64" pts:%s pts_time:%s pos:%"PRId64" "
           "fmt:%s sar:%d/%d s:%dx%d i:%c iskey:%d type:%c "
           "checksum:%08X plane_checksum:[%08X",
           inlink->frame_count,
           av_ts2str(frame->pts), av_ts2timestr(frame->pts, &inlink->time_base), av_frame_get_pkt_pos(frame),
           desc->name,
           frame->sample_aspect_ratio.num, frame->sample_aspect_ratio.den,
           frame->width, frame->height,
           !frame->interlaced_frame ? 'P' :         /* Progressive  */
           frame->top_field_first   ? 'T' : 'B',    /* Top / Bottom */
           frame->key_frame,
           av_get_picture_type_char(frame->pict_type),
           checksum, plane_checksum[0]);

    for (plane = 1; plane < 4 && frame->data[plane] && frame->linesize[plane]; plane++)
        av_log(ctx, AV_LOG_INFO, " %08X", plane_checksum[plane]);
    av_log(ctx, AV_LOG_INFO, "]\n");

    return ff_filter_frame(inlink->dst->outputs[0], frame);
}
예제 #8
0
static int framecrc_write_packet(struct AVFormatContext *s, AVPacket *pkt)
{
    uint32_t crc = av_adler32_update(0, pkt->data, pkt->size);
    char buf[256];

    snprintf(buf, sizeof(buf), "%d, %"PRId64", %d, 0x%08x\n", pkt->stream_index, pkt->dts, pkt->size, crc);
    avio_write(s->pb, buf, strlen(buf));
    avio_flush(s->pb);
    return 0;
}
예제 #9
0
static int filter_samples(AVFilterLink *inlink, AVFilterBufferRef *buf)
{
    AVFilterContext *ctx = inlink->dst;
    AShowInfoContext *s  = ctx->priv;
    char chlayout_str[128];
    uint32_t checksum = 0;
    int channels    = av_get_channel_layout_nb_channels(buf->audio->channel_layout);
    int planar      = av_sample_fmt_is_planar(buf->format);
    int block_align = av_get_bytes_per_sample(buf->format) * (planar ? 1 : channels);
    int data_size   = buf->audio->nb_samples * block_align;
    int planes      = planar ? channels : 1;
    int i;

    for (i = 0; i < planes; i++) {
        uint8_t *data = buf->extended_data[i];

        s->plane_checksums[i] = av_adler32_update(0, data, data_size);
        checksum = i ? av_adler32_update(checksum, data, data_size) :
                       s->plane_checksums[0];
    }

    av_get_channel_layout_string(chlayout_str, sizeof(chlayout_str), -1,
                                 buf->audio->channel_layout);

    av_log(ctx, AV_LOG_INFO,
           "n:%"PRIu64" pts:%"PRId64" pts_time:%f "
           "fmt:%s chlayout:%s rate:%d nb_samples:%d "
           "checksum:%08X ",
           s->frame, buf->pts, buf->pts * av_q2d(inlink->time_base),
           av_get_sample_fmt_name(buf->format), chlayout_str,
           buf->audio->sample_rate, buf->audio->nb_samples,
           checksum);

    av_log(ctx, AV_LOG_INFO, "plane_checksums: [ ");
    for (i = 0; i < planes; i++)
        av_log(ctx, AV_LOG_INFO, "%08X ", s->plane_checksums[i]);
    av_log(ctx, AV_LOG_INFO, "]\n");

    s->frame++;
    return ff_filter_samples(inlink->dst->outputs[0], buf);
}
예제 #10
0
파일: vf_showinfo.c 프로젝트: Arcen/libav
static void end_frame(AVFilterLink *inlink)
{
    AVFilterContext *ctx = inlink->dst;
    ShowInfoContext *showinfo = ctx->priv;
    AVFilterBufferRef *picref = inlink->cur_buf;
    uint32_t plane_checksum[4] = {0}, checksum = 0;
    int i, plane, vsub = av_pix_fmt_descriptors[inlink->format].log2_chroma_h;

    for (plane = 0; picref->data[plane] && plane < 4; plane++) {
        size_t linesize = av_image_get_linesize(picref->format, picref->video->w, plane);
        uint8_t *data = picref->data[plane];
        int h = plane == 1 || plane == 2 ? inlink->h >> vsub : inlink->h;

        for (i = 0; i < h; i++) {
            plane_checksum[plane] = av_adler32_update(plane_checksum[plane], data, linesize);
            checksum = av_adler32_update(checksum, data, linesize);
            data += picref->linesize[plane];
        }
    }

    av_log(ctx, AV_LOG_INFO,
           "n:%d pts:%"PRId64" pts_time:%f pos:%"PRId64" "
           "fmt:%s sar:%d/%d s:%dx%d i:%c iskey:%d type:%c "
           "checksum:%u plane_checksum:[%u %u %u %u]\n",
           showinfo->frame,
           picref->pts, picref->pts * av_q2d(inlink->time_base), picref->pos,
           av_pix_fmt_descriptors[picref->format].name,
           picref->video->pixel_aspect.num, picref->video->pixel_aspect.den,
           picref->video->w, picref->video->h,
           !picref->video->interlaced     ? 'P' :         /* Progressive  */
           picref->video->top_field_first ? 'T' : 'B',    /* Top / Bottom */
           picref->video->key_frame,
           av_get_picture_type_char(picref->video->pict_type),
           checksum, plane_checksum[0], plane_checksum[1], plane_checksum[2], plane_checksum[3]);

    showinfo->frame++;
    ff_end_frame(inlink->dst->outputs[0]);
}
예제 #11
0
static int framecrc_write_header(struct AVFormatContext *s)
{
    int i;
    for (i = 0; i < s->nb_streams; i++) {
        AVStream *st = s->streams[i];
        AVCodecContext *avctx = st->codec;
        if (avctx->extradata) {
            uint32_t crc = av_adler32_update(0, avctx->extradata, avctx->extradata_size);
            avio_printf(s->pb, "#extradata %d: %8d, 0x%08"PRIx32"\n",
                        i, avctx->extradata_size, crc);
        }
    }

    return ff_framehash_write_header(s);
}
예제 #12
0
static int compute_crc_of_packets(AVFormatContext *fmt_ctx, int video_stream,
                                AVCodecContext *ctx, AVFrame *fr, uint64_t ts_start, uint64_t ts_end, int no_seeking)
{
    int number_of_written_bytes;
    int got_frame = 0;
    int result;
    int end_of_stream = 0;
    int byte_buffer_size;
    uint8_t *byte_buffer;
    int64_t crc;
    AVPacket pkt;

    byte_buffer_size = av_image_get_buffer_size(ctx->pix_fmt, ctx->width, ctx->height, 16);
    byte_buffer = av_malloc(byte_buffer_size);
    if (!byte_buffer) {
        av_log(NULL, AV_LOG_ERROR, "Can't allocate buffer\n");
        return AVERROR(ENOMEM);
    }

    if (!no_seeking) {
        result = av_seek_frame(fmt_ctx, video_stream, ts_start, AVSEEK_FLAG_ANY);
        printf("Seeking to %"PRId64", computing crc for frames with pts < %"PRId64"\n", ts_start, ts_end);
        if (result < 0) {
            av_log(NULL, AV_LOG_ERROR, "Error in seeking\n");
            return result;
        }
        avcodec_flush_buffers(ctx);
    }

    av_init_packet(&pkt);
    do {
        if (!end_of_stream)
            if (av_read_frame(fmt_ctx, &pkt) < 0)
                end_of_stream = 1;
        if (end_of_stream) {
            pkt.data = NULL;
            pkt.size = 0;
        }
        if (pkt.stream_index == video_stream || end_of_stream) {
            got_frame = 0;
            if ((pkt.pts == AV_NOPTS_VALUE) && (!end_of_stream)) {
                av_log(NULL, AV_LOG_ERROR, "Error: frames doesn't have pts values\n");
                return -1;
            }
            result = avcodec_decode_video2(ctx, fr, &got_frame, &pkt);
            if (result < 0) {
                av_log(NULL, AV_LOG_ERROR, "Error decoding frame\n");
                return result;
            }
            if (got_frame) {
                number_of_written_bytes = av_image_copy_to_buffer(byte_buffer, byte_buffer_size,
                                        (const uint8_t* const *)fr->data, (const int*) fr->linesize,
                                        ctx->pix_fmt, ctx->width, ctx->height, 1);
                if (number_of_written_bytes < 0) {
                    av_log(NULL, AV_LOG_ERROR, "Can't copy image to buffer\n");
                    return number_of_written_bytes;
                }
                if ((fr->pkt_pts > ts_end) && (!no_seeking))
                    break;
                crc = av_adler32_update(0, (const uint8_t*)byte_buffer, number_of_written_bytes);
                printf("%10"PRId64", 0x%08lx\n", fr->pkt_pts, crc);
                if (no_seeking) {
                    if (add_crc_to_array(crc, fr->pkt_pts) < 0)
                        return -1;
                }
                else {
                    if (compare_crc_in_array(crc, fr->pkt_pts) < 0)
                        return -1;
                }
            }
        }
        av_packet_unref(&pkt);
        av_init_packet(&pkt);
    } while ((!end_of_stream || got_frame) && (no_seeking || (fr->pkt_pts + av_frame_get_pkt_duration(fr) <= ts_end)));

    av_packet_unref(&pkt);
    av_freep(&byte_buffer);

    return 0;
}
예제 #13
0
static int filter_frame(AVFilterLink *inlink, AVFrame *frame)
{
    AVFilterContext *ctx = inlink->dst;
    const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(inlink->format);
    uint32_t plane_checksum[4] = {0}, checksum = 0;
    int64_t sum[4] = {0}, sum2[4] = {0};
    int32_t pixelcount[4] = {0};
    int i, plane, vsub = desc->log2_chroma_h;
#ifdef IDE_COMPILE
	char tmp1[32] = {0};
	char tmp2[32] = {0};
#endif

    for (plane = 0; plane < 4 && frame->data[plane] && frame->linesize[plane]; plane++) {
        int64_t linesize = av_image_get_linesize(frame->format, frame->width, plane);
        uint8_t *data = frame->data[plane];
        int h = plane == 1 || plane == 2 ? FF_CEIL_RSHIFT(inlink->h, vsub) : inlink->h;

        if (linesize < 0)
            return linesize;

        for (i = 0; i < h; i++) {
            plane_checksum[plane] = av_adler32_update(plane_checksum[plane], data, linesize);
            checksum = av_adler32_update(checksum, data, linesize);

            update_sample_stats(data, linesize, sum+plane, sum2+plane);
            pixelcount[plane] += linesize;
            data += frame->linesize[plane];
        }
    }

#ifdef IDE_COMPILE
	av_log(ctx, AV_LOG_INFO,
           "n:%"PRId64" pts:%s pts_time:%s pos:%"PRId64" "
           "fmt:%s sar:%d/%d s:%dx%d i:%c iskey:%d type:%c "
           "checksum:%08"PRIX32" plane_checksum:[%08"PRIX32,
           inlink->frame_count,
           av_ts_make_string(tmp1, frame->pts), av_ts_make_time_string(tmp2, frame->pts, &inlink->time_base), av_frame_get_pkt_pos(frame),
           desc->name,
           frame->sample_aspect_ratio.num, frame->sample_aspect_ratio.den,
           frame->width, frame->height,
           !frame->interlaced_frame ? 'P' :         /* Progressive  */
           frame->top_field_first   ? 'T' : 'B',    /* Top / Bottom */
           frame->key_frame,
           av_get_picture_type_char(frame->pict_type),
           checksum, plane_checksum[0]);
#else
	av_log(ctx, AV_LOG_INFO,
           "n:%"PRId64" pts:%s pts_time:%s pos:%"PRId64" "
           "fmt:%s sar:%d/%d s:%dx%d i:%c iskey:%d type:%c "
           "checksum:%08"PRIX32" plane_checksum:[%08"PRIX32,
           inlink->frame_count,
           av_ts2str(frame->pts), av_ts2timestr(frame->pts, &inlink->time_base), av_frame_get_pkt_pos(frame),
           desc->name,
           frame->sample_aspect_ratio.num, frame->sample_aspect_ratio.den,
           frame->width, frame->height,
           !frame->interlaced_frame ? 'P' :         /* Progressive  */
           frame->top_field_first   ? 'T' : 'B',    /* Top / Bottom */
           frame->key_frame,
           av_get_picture_type_char(frame->pict_type),
           checksum, plane_checksum[0]);
#endif

    for (plane = 1; plane < 4 && frame->data[plane] && frame->linesize[plane]; plane++)
        av_log(ctx, AV_LOG_INFO, " %08"PRIX32, plane_checksum[plane]);
    av_log(ctx, AV_LOG_INFO, "] mean:[");
    for (plane = 0; plane < 4 && frame->data[plane] && frame->linesize[plane]; plane++)
        av_log(ctx, AV_LOG_INFO, "%"PRId64" ", (sum[plane] + pixelcount[plane]/2) / pixelcount[plane]);
    av_log(ctx, AV_LOG_INFO, "\b] stdev:[");
    for (plane = 0; plane < 4 && frame->data[plane] && frame->linesize[plane]; plane++)
        av_log(ctx, AV_LOG_INFO, "%3.1f ",
               sqrt((sum2[plane] - sum[plane]*(double)sum[plane]/pixelcount[plane])/pixelcount[plane]));
    av_log(ctx, AV_LOG_INFO, "\b]\n");

    for (i = 0; i < frame->nb_side_data; i++) {
        AVFrameSideData *sd = frame->side_data[i];

        av_log(ctx, AV_LOG_INFO, "  side data - ");
        switch (sd->type) {
        case AV_FRAME_DATA_PANSCAN:
            av_log(ctx, AV_LOG_INFO, "pan/scan");
            break;
        case AV_FRAME_DATA_A53_CC:
            av_log(ctx, AV_LOG_INFO, "A/53 closed captions (%d bytes)", sd->size);
            break;
        case AV_FRAME_DATA_STEREO3D:
            dump_stereo3d(ctx, sd);
            break;
        case AV_FRAME_DATA_DISPLAYMATRIX:
            av_log(ctx, AV_LOG_INFO, "displaymatrix: rotation of %.2f degrees",
                   av_display_rotation_get((int32_t *)sd->data));
            break;
        case AV_FRAME_DATA_AFD:
            av_log(ctx, AV_LOG_INFO, "afd: value of %"PRIu8, sd->data[0]);
            break;
        default:
            av_log(ctx, AV_LOG_WARNING, "unknown side data type %d (%d bytes)",
                   sd->type, sd->size);
            break;
        }

        av_log(ctx, AV_LOG_INFO, "\n");
    }

    return ff_filter_frame(inlink->dst->outputs[0], frame);
}
예제 #14
0
static int filter_frame(AVFilterLink *inlink, AVFrame *frame)
{
    AVFilterContext *ctx = inlink->dst;
    const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(inlink->format);
    uint32_t plane_checksum[4] = {0}, checksum = 0;
    int i, plane, vsub = desc->log2_chroma_h;

    for (plane = 0; plane < 4 && frame->data[plane] && frame->linesize[plane]; plane++) {
        int64_t linesize = av_image_get_linesize(frame->format, frame->width, plane);
        uint8_t *data = frame->data[plane];
        int h = plane == 1 || plane == 2 ? FF_CEIL_RSHIFT(inlink->h, vsub) : inlink->h;

        if (linesize < 0)
            return linesize;

        for (i = 0; i < h; i++) {
            plane_checksum[plane] = av_adler32_update(plane_checksum[plane], data, linesize);
            checksum = av_adler32_update(checksum, data, linesize);
            data += frame->linesize[plane];
        }
    }

    av_log(ctx, AV_LOG_INFO,
           "n:%"PRId64" pts:%s pts_time:%s pos:%"PRId64" "
           "fmt:%s sar:%d/%d s:%dx%d i:%c iskey:%d type:%c "
           "checksum:%08"PRIX32" plane_checksum:[%08"PRIX32,
           inlink->frame_count,
           av_ts2str(frame->pts), av_ts2timestr(frame->pts, &inlink->time_base), av_frame_get_pkt_pos(frame),
           desc->name,
           frame->sample_aspect_ratio.num, frame->sample_aspect_ratio.den,
           frame->width, frame->height,
           !frame->interlaced_frame ? 'P' :         /* Progressive  */
           frame->top_field_first   ? 'T' : 'B',    /* Top / Bottom */
           frame->key_frame,
           av_get_picture_type_char(frame->pict_type),
           checksum, plane_checksum[0]);

    for (plane = 1; plane < 4 && frame->data[plane] && frame->linesize[plane]; plane++)
        av_log(ctx, AV_LOG_INFO, " %08"PRIX32, plane_checksum[plane]);
    av_log(ctx, AV_LOG_INFO, "]\n");

    for (i = 0; i < frame->nb_side_data; i++) {
        AVFrameSideData *sd = frame->side_data[i];

        av_log(ctx, AV_LOG_INFO, "  side data - ");
        switch (sd->type) {
        case AV_FRAME_DATA_PANSCAN:
            av_log(ctx, AV_LOG_INFO, "pan/scan");
            break;
        case AV_FRAME_DATA_A53_CC:
            av_log(ctx, AV_LOG_INFO, "A/53 closed captions (%d bytes)", sd->size);
            break;
        case AV_FRAME_DATA_STEREO3D:
            dump_stereo3d(ctx, sd);
            break;
        default:
            av_log(ctx, AV_LOG_WARNING, "unknown side data type %d (%d bytes)",
                   sd->type, sd->size);
            break;
        }

        av_log(ctx, AV_LOG_INFO, "\n");
    }

    return ff_filter_frame(inlink->dst->outputs[0], frame);
}
예제 #15
0
static int crc_write_packet(struct AVFormatContext *s, AVPacket *pkt)
{
    CRCState *crc = s->priv_data;
    crc->crcval = av_adler32_update(crc->crcval, pkt->data, pkt->size);
    return 0;
}
예제 #16
0
static int filter_frame(AVFilterLink *inlink, AVFrame *frame)
{
    AVFilterContext *ctx = inlink->dst;
    ShowInfoContext *showinfo = ctx->priv;
    const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(inlink->format);
    uint32_t plane_checksum[4] = {0}, checksum = 0;
    int i, plane, vsub = desc->log2_chroma_h;

    for (plane = 0; frame->data[plane] && plane < 4; plane++) {
        size_t linesize = av_image_get_linesize(frame->format, frame->width, plane);
        uint8_t *data = frame->data[plane];
        int h = plane == 1 || plane == 2 ? inlink->h >> vsub : inlink->h;

        for (i = 0; i < h; i++) {
            plane_checksum[plane] = av_adler32_update(plane_checksum[plane], data, linesize);
            checksum = av_adler32_update(checksum, data, linesize);
            data += frame->linesize[plane];
        }
    }

    av_log(ctx, AV_LOG_INFO,
           "n:%d pts:%"PRId64" pts_time:%f "
           "fmt:%s sar:%d/%d s:%dx%d i:%c iskey:%d type:%c "
           "checksum:%"PRIu32" plane_checksum:[%"PRIu32" %"PRIu32" %"PRIu32" %"PRIu32"]\n",
           showinfo->frame,
           frame->pts, frame->pts * av_q2d(inlink->time_base),
           desc->name,
           frame->sample_aspect_ratio.num, frame->sample_aspect_ratio.den,
           frame->width, frame->height,
           !frame->interlaced_frame ? 'P' :         /* Progressive  */
           frame->top_field_first   ? 'T' : 'B',    /* Top / Bottom */
           frame->key_frame,
           av_get_picture_type_char(frame->pict_type),
           checksum, plane_checksum[0], plane_checksum[1], plane_checksum[2], plane_checksum[3]);

    for (i = 0; i < frame->nb_side_data; i++) {
        AVFrameSideData *sd = frame->side_data[i];

        av_log(ctx, AV_LOG_INFO, "  side data - ");
        switch (sd->type) {
        case AV_FRAME_DATA_PANSCAN:
            av_log(ctx, AV_LOG_INFO, "pan/scan");
            break;
        case AV_FRAME_DATA_A53_CC:
            av_log(ctx, AV_LOG_INFO, "A/53 closed captions (%d bytes)", sd->size);
            break;
        case AV_FRAME_DATA_STEREO3D:
            dump_stereo3d(ctx, sd);
            break;
        case AV_FRAME_DATA_DISPLAYMATRIX:
            av_log(ctx, AV_LOG_INFO, "displaymatrix: rotation of %.2f degrees",
                   av_display_rotation_get((int32_t *)sd->data));
            break;
        case AV_FRAME_DATA_AFD:
            av_log(ctx, AV_LOG_INFO, "afd: value of %"PRIu8, sd->data[0]);
            break;
        default:
            av_log(ctx, AV_LOG_WARNING, "unknown side data type %d (%d bytes)",
                   sd->type, sd->size);
            break;
        }

        av_log(ctx, AV_LOG_INFO, "\n");
    }

    showinfo->frame++;
    return ff_filter_frame(inlink->dst->outputs[0], frame);
}
예제 #17
0
static int video_decode_example(const char *input_filename)
{
    AVCodec *codec = NULL;
    AVCodecContext *ctx= NULL;
    AVCodecParameters *origin_par = NULL;
    AVFrame *fr = NULL;
    uint8_t *byte_buffer = NULL;
    AVPacket pkt;
    AVFormatContext *fmt_ctx = NULL;
    int number_of_written_bytes;
    int video_stream;
    int got_frame = 0;
    int byte_buffer_size;
    int i = 0;
    int result;
    int end_of_stream = 0;

    result = avformat_open_input(&fmt_ctx, input_filename, NULL, NULL);
    if (result < 0) {
        av_log(NULL, AV_LOG_ERROR, "Can't open file\n");
        return result;
    }

    result = avformat_find_stream_info(fmt_ctx, NULL);
    if (result < 0) {
        av_log(NULL, AV_LOG_ERROR, "Can't get stream info\n");
        return result;
    }

    video_stream = av_find_best_stream(fmt_ctx, AVMEDIA_TYPE_VIDEO, -1, -1, NULL, 0);
    if (video_stream < 0) {
      av_log(NULL, AV_LOG_ERROR, "Can't find video stream in input file\n");
      return -1;
    }

    origin_par = fmt_ctx->streams[video_stream]->codecpar;

    codec = avcodec_find_decoder(origin_par->codec_id);
    if (!codec) {
        av_log(NULL, AV_LOG_ERROR, "Can't find decoder\n");
        return -1;
    }

    ctx = avcodec_alloc_context3(codec);
    if (!ctx) {
        av_log(NULL, AV_LOG_ERROR, "Can't allocate decoder context\n");
        return AVERROR(ENOMEM);
    }

    result = avcodec_parameters_to_context(ctx, origin_par);
    if (result) {
        av_log(NULL, AV_LOG_ERROR, "Can't copy decoder context\n");
        return result;
    }

    result = avcodec_open2(ctx, codec, NULL);
    if (result < 0) {
        av_log(ctx, AV_LOG_ERROR, "Can't open decoder\n");
        return result;
    }

    fr = av_frame_alloc();
    if (!fr) {
        av_log(NULL, AV_LOG_ERROR, "Can't allocate frame\n");
        return AVERROR(ENOMEM);
    }

    byte_buffer_size = av_image_get_buffer_size(ctx->pix_fmt, ctx->width, ctx->height, 16);
    byte_buffer = av_malloc(byte_buffer_size);
    if (!byte_buffer) {
        av_log(NULL, AV_LOG_ERROR, "Can't allocate buffer\n");
        return AVERROR(ENOMEM);
    }

    printf("#tb %d: %d/%d\n", video_stream, fmt_ctx->streams[video_stream]->time_base.num, fmt_ctx->streams[video_stream]->time_base.den);
    i = 0;
    av_init_packet(&pkt);
    do {
        if (!end_of_stream)
            if (av_read_frame(fmt_ctx, &pkt) < 0)
                end_of_stream = 1;
        if (end_of_stream) {
            pkt.data = NULL;
            pkt.size = 0;
        }
        if (pkt.stream_index == video_stream || end_of_stream) {
            got_frame = 0;
            if (pkt.pts == AV_NOPTS_VALUE)
                pkt.pts = pkt.dts = i;
            result = avcodec_decode_video2(ctx, fr, &got_frame, &pkt);
            if (result < 0) {
                av_log(NULL, AV_LOG_ERROR, "Error decoding frame\n");
                return result;
            }
            if (got_frame) {
                number_of_written_bytes = av_image_copy_to_buffer(byte_buffer, byte_buffer_size,
                                        (const uint8_t* const *)fr->data, (const int*) fr->linesize,
                                        ctx->pix_fmt, ctx->width, ctx->height, 1);
                if (number_of_written_bytes < 0) {
                    av_log(NULL, AV_LOG_ERROR, "Can't copy image to buffer\n");
                    return number_of_written_bytes;
                }
                printf("%d, %10"PRId64", %10"PRId64", %8"PRId64", %8d, 0x%08lx\n", video_stream,
                        fr->pts, fr->pkt_dts, fr->pkt_duration,
                        number_of_written_bytes, av_adler32_update(0, (const uint8_t*)byte_buffer, number_of_written_bytes));
            }
            av_packet_unref(&pkt);
            av_init_packet(&pkt);
        }
        i++;
    } while (!end_of_stream || got_frame);

    av_packet_unref(&pkt);
    av_frame_free(&fr);
    avcodec_close(ctx);
    avformat_close_input(&fmt_ctx);
    avcodec_free_context(&ctx);
    av_freep(&byte_buffer);
    return 0;
}
예제 #18
0
static int filter_frame(AVFilterLink *inlink, AVFrame *buf)
{
    AVFilterContext *ctx = inlink->dst;
    AShowInfoContext *s  = ctx->priv;
    char chlayout_str[128];
    uint32_t checksum = 0;
    int channels    = inlink->channels;
    int planar      = av_sample_fmt_is_planar(buf->format);
    int block_align = av_get_bytes_per_sample(buf->format) * (planar ? 1 : channels);
    int data_size   = buf->nb_samples * block_align;
    int planes      = planar ? channels : 1;
    int i;
    void *tmp_ptr = av_realloc_array(s->plane_checksums, channels, sizeof(*s->plane_checksums));

    if (!tmp_ptr)
        return AVERROR(ENOMEM);
    s->plane_checksums = tmp_ptr;

    for (i = 0; i < planes; i++) {
        uint8_t *data = buf->extended_data[i];

        s->plane_checksums[i] = av_adler32_update(0, data, data_size);
        checksum = i ? av_adler32_update(checksum, data, data_size) :
                       s->plane_checksums[0];
    }

    av_get_channel_layout_string(chlayout_str, sizeof(chlayout_str), -1,
                                 buf->channel_layout);

    av_log(ctx, AV_LOG_INFO,
           "n:%"PRId64" pts:%s pts_time:%s pos:%"PRId64" "
           "fmt:%s channels:%d chlayout:%s rate:%d nb_samples:%d "
           "checksum:%08"PRIX32" ",
           inlink->frame_count_out,
           av_ts2str(buf->pts), av_ts2timestr(buf->pts, &inlink->time_base),
           av_frame_get_pkt_pos(buf),
           av_get_sample_fmt_name(buf->format), av_frame_get_channels(buf), chlayout_str,
           buf->sample_rate, buf->nb_samples,
           checksum);

    av_log(ctx, AV_LOG_INFO, "plane_checksums: [ ");
    for (i = 0; i < planes; i++)
        av_log(ctx, AV_LOG_INFO, "%08"PRIX32" ", s->plane_checksums[i]);
    av_log(ctx, AV_LOG_INFO, "]\n");

    for (i = 0; i < buf->nb_side_data; i++) {
        AVFrameSideData *sd = buf->side_data[i];

        av_log(ctx, AV_LOG_INFO, "  side data - ");
        switch (sd->type) {
        case AV_FRAME_DATA_MATRIXENCODING: dump_matrixenc (ctx, sd); break;
        case AV_FRAME_DATA_DOWNMIX_INFO:   dump_downmix   (ctx, sd); break;
        case AV_FRAME_DATA_REPLAYGAIN:     dump_replaygain(ctx, sd); break;
        case AV_FRAME_DATA_AUDIO_SERVICE_TYPE: dump_audio_service_type(ctx, sd); break;
        default:                           dump_unknown   (ctx, sd); break;
        }

        av_log(ctx, AV_LOG_INFO, "\n");
    }

    return ff_filter_frame(inlink->dst->outputs[0], buf);
}
예제 #19
0
파일: vdec.c 프로젝트: SelfImp/m75
static int uvvp_vdec_ioctl(struct file *file,
							unsigned int cmd, unsigned long arg)
{
int ret=0;
    int i, j;
    //int recv_buf[256];
    //int send_buf[256];
    //int num = 0;
    
    // For UVVP_VDEC_TEST_VERSION_1
    int reg_in = 0;
    int reg_out = 0;

    // For UVVP_VDEC_TEST_VERSION_2
    int mem_sz = 1;
    UCHAR *p = NULL;
    unsigned int u4Align = 1024;
    unsigned int u4Size = 16384;
    unsigned char *buf_data;
    unsigned char *buf_data2;
    UINT32 u4RetValue;

    // For UVVP_VDEC_TEST_VERSION_3
    struct termios settings; 
    struct file *fd = 0;
    mm_segment_t oldfs;
    unsigned long crc = 0;
    unsigned long own_crc = 0;
    int frame_start = 0;
    int frame_end= 0;
    int file_num = 0;
    int file_len = 0;
    int read_len = 0;
    int tmp_buf[256];

    // For speed measurement
    struct timeval tv1;
    struct timeval tv2;

//struct file * pfilename;
  VDEC_PARAM_T *param;
#if (VDEC_MVC_SUPPORT)
  VDEC_PARAM_T *param1;
#endif
printk("\r\n******** uvvp_vdec_ioctl cmd[%d]********\r\n",cmd);
param = kmalloc(sizeof(VDEC_PARAM_T), GFP_KERNEL);
#if (VDEC_MVC_SUPPORT)
  param1 = kmalloc(sizeof(VDEC_PARAM_T), GFP_KERNEL); 
#endif

	switch (cmd) {
		//  General TEST CASE
		case UVVP_VDEC_TEST_VERSION:
			param->u4InstanceId = 0;
			param->u4Mode = 0;
                        #if (VDEC_MVC_SUPPORT)
                        param->fgMVCType = TRUE;
                        #else
                        param->fgMVCType = FALSE;
                        #endif
			printk("\r\n******** uvvp_vdec_ioctl UVVP_VDEC_TEST_VERSION ********\r\n");	
#if VDEC_VP8_WEBP_SUPPORT_ME2_INTEGRATION
            vVDecVerifyThread(param);
            vVerInitVDec(0);
            vVParserProc(0);
            vVDecProc(0);
#if VP8_MB_ROW_MODE_SUPPORT_ME2_INTEGRATION
            while(1)
            {
                u4RetValue = vVerVP8DecEndProc_MB_ROW_START(0);
                if (u4RetValue == vVerResult_MB_ROW_DONE)
                {
                    printk("\n\n======== MB ROW DONE!! ========\n\n");
                }
                else if(u4RetValue == vVerResult_FRAME_DONE)
                {
                    printk("\n\n======== FRAME DONE!! ========\n\n");
                    break;
                }
                else
                {
                    printk("\n\n[ERROR]======== decode timeout!! ========\n\n");
                    break;
                }
            }
            vChkVDec_Webp_Row_Mode(0);
#else            
            vChkVDec(0);
#endif
#ifdef PCFILE_WRITE  
            if(_tInFileInfo[param->u4InstanceId].pFile)
            {
              fclose(_tInFileInfo[param->u4InstanceId].pFile);
            }
#endif
            vVerifyVDecIsrStop(param->u4InstanceId);
            vMemoryFree(param->u4InstanceId);
#ifdef SATA_HDD_READ_SUPPORT
#ifdef SATA_HDD_FS_SUPPORT
            if (_tFileListInfo[param->u4InstanceId].i4FileId != 0xFFFFFFFF)
            {
                // fgHDDFsCloseFile(u4InstID); // temp avoid system crash
                _tFileListInfo[param->u4InstanceId].i4FileId = 0xFFFFFFFF;
            }
            //FS mount
            fgHDDFsUnMount(0);
#endif
#endif
#else
			MPV_thread = kthread_run(vVDecVerifyThread, param, "rt8192cu_rtw_xmit_thread");
			if (IS_ERR(MPV_thread)) { 
				printk("[%s]: failed to create MPV thread\n", __FUNCTION__);
				return 0;	
				}
                        else
                        {
                            printk("Creat mpv0 thread ok!\n");
                        }  
//			break;					
//		case UVVP_VDEC_TEST_VERSION_1:
                        #if (VDEC_MVC_SUPPORT)
			param1->u4InstanceId = 1;
			param1->u4Mode = 0;
                        param1->fgMVCType = TRUE;
                        msleep(2);
			MPV_thread = kthread_run(vVDecVerifyThread, param1, "rt8192cu_rtw_xmit_thread");
			if (IS_ERR(MPV_thread)) { 
				printk("[%s]: failed to create MPV thread\n", __FUNCTION__);
				return 0;	
				}
                        else
                        {
                            printk("Creat mpv1 thread ok!\n");
                        }
                        #endif
#endif                        
			break;
        case UVVP_VDEC_TEST_VERSION_1:
            printk("UVVP_VDEC_TEST_VERSION_1\n");

            reg_in = 0x1;
            reg_out = 0;
            MFV_HW_WRITE(VDEC_GCON_BASE, reg_in);
            reg_out = MFV_HW_READ(VDEC_GCON_BASE);
            printk("GCON write 0x%x, read 0x%x, %s\n", reg_in, reg_out, reg_in == reg_out ? "Pass":"******");
            
            reg_in = 0xFFFFFFFF;
            reg_out = 0;
            MFV_HW_WRITE((VDEC_BASE + MC_BASE_OFFSET + OFFSET_R1Y_ADD), reg_in);
            reg_out = MFV_HW_READ((VDEC_BASE + MC_BASE_OFFSET + OFFSET_R1Y_ADD));
            printk("OFFSET_R1Y_ADD write 0x%x, read 0x%x, mask 0x%x, %s\n", reg_in, reg_out, Y_MASK, (reg_in & Y_MASK) == reg_out ? "Pass":"******");
            
            reg_in = 0xFFFFFFFF;
            reg_out = 0;
            MFV_HW_WRITE((VDEC_BASE + MC_BASE_OFFSET + OFFSET_R1C_ADD), reg_in);
            reg_out = MFV_HW_READ((VDEC_BASE + MC_BASE_OFFSET + OFFSET_R1C_ADD));
            printk("OFFSET_R1C_ADD write 0x%x, read 0x%x, mask 0x%x, %s\n", reg_in, reg_out, C_MASK, (reg_in & C_MASK) == reg_out ? "Pass":"******");
            
            reg_in = 0xFFFFFFFF;
            reg_out = 0;
            MFV_HW_WRITE((VDEC_BASE + MC_BASE_OFFSET + OFFSET_R2Y_ADD), reg_in);
            reg_out = MFV_HW_READ((VDEC_BASE + MC_BASE_OFFSET + OFFSET_R2Y_ADD));
            printk("OFFSET_R2Y_ADD write 0x%x, read 0x%x, mask 0x%x, %s\n", reg_in, reg_out, Y_MASK, (reg_in & Y_MASK) == reg_out ? "Pass":"******");

            reg_in = 0xFFFFFFFF;
            reg_out = 0;
            MFV_HW_WRITE((VDEC_BASE + MC_BASE_OFFSET + OFFSET_R2C_ADD), reg_in);
            reg_out = MFV_HW_READ((VDEC_BASE + MC_BASE_OFFSET + OFFSET_R2C_ADD));
            printk("OFFSET_R2C_ADD write 0x%x, read 0x%x, mask 0x%x, %s\n", reg_in, reg_out, C_MASK, (reg_in & C_MASK) == reg_out ? "Pass":"******");

            break;
		case UVVP_VDEC_TEST_VERSION_2:
		    printk("UVVP_VDEC_TEST_VERSION_2\n");

            printk("=== vmalloc memory speed test ===\n");
            
            do_gettimeofday(&tv1);
            buf_data = (unsigned char *)vmalloc(TESTDATA_BUFFER_SZ);
            buf_data2 = (unsigned char *)vmalloc(TESTDATA_BUFFER_SZ); 
            do_gettimeofday(&tv2);
            calc_time_diff(&tv1, &tv2);
            printk("Allocated %d + %dMB in %d sec %d usec\n", TESTDATA_BUFFER_SZ/1024/1024, TESTDATA_BUFFER_SZ/1024/1024, tv2.tv_sec, tv2.tv_usec);

            do_gettimeofday(&tv1);
            memset(buf_data, 0, TESTDATA_BUFFER_SZ);
            memset(buf_data2, 1, TESTDATA_BUFFER_SZ);
            do_gettimeofday(&tv2);
            calc_time_diff(&tv1, &tv2);
            printk("memset %d + %dMB in %d sec %d usec\n", TESTDATA_BUFFER_SZ/1024/1024, TESTDATA_BUFFER_SZ/1024/1024, tv2.tv_sec, tv2.tv_usec);

            do_gettimeofday(&tv1);
            memcpy(buf_data, buf_data2, TESTDATA_BUFFER_SZ);
            do_gettimeofday(&tv2);
            calc_time_diff(&tv1, &tv2);
            printk("memcpy %dMB in %d sec %d usec\n", TESTDATA_BUFFER_SZ/1024/1024, tv2.tv_sec, tv2.tv_usec);

            vfree(buf_data);
            vfree(buf_data2);

            printk("=== ioremap_nocache memory speed test ===\n");
            do_gettimeofday(&tv1);
            buf_data = g_pu1AllocSA;
            buf_data2 = g_pu1AllocSA + TESTDATA_BUFFER_SZ;
            buf_data = ioremap_nocache(buf_data, TESTDATA_BUFFER_SZ);
            buf_data2 = ioremap_nocache(buf_data2, TESTDATA_BUFFER_SZ);
            do_gettimeofday(&tv2);
            calc_time_diff(&tv1, &tv2);
            printk("ioremap %d + %dMB in %d sec %d usec\n", TESTDATA_BUFFER_SZ/1024/1024, TESTDATA_BUFFER_SZ/1024/1024, tv2.tv_sec, tv2.tv_usec);

            do_gettimeofday(&tv1);
            memset(buf_data, 0, TESTDATA_BUFFER_SZ);
            memset(buf_data2, 1, TESTDATA_BUFFER_SZ);
            do_gettimeofday(&tv2);
            calc_time_diff(&tv1, &tv2);
            printk("memset %d + %dMB in %d sec %d usec\n", TESTDATA_BUFFER_SZ/1024/1024, TESTDATA_BUFFER_SZ/1024/1024, tv2.tv_sec, tv2.tv_usec);

            do_gettimeofday(&tv1);
            memcpy(buf_data, buf_data2, TESTDATA_BUFFER_SZ);
            do_gettimeofday(&tv2);
            calc_time_diff(&tv1, &tv2);
            printk("memcpy %dMB in %d sec %d usec\n", TESTDATA_BUFFER_SZ/1024/1024, tv2.tv_sec, tv2.tv_usec);
            
            iounmap(buf_data);
            iounmap(buf_data2);            

            printk("=== ioremap write test ===\n");
            p = g_pu1AllocSA;
            p = ((UINT32)p + u4Align-1) & (~(u4Align - 1));
            printk("p physical addr 0x%x\n", p);
            p = ioremap_nocache(p, u4Size);
            printk("p virtual addr 0x%x\n", p);
            *p = 'S';
            *(p+u4Size-1) = 'E';
            printk("p %c %c\n", *p, *(p+u4Size-1));
            
            iounmap(p);
            
/*

            while (1)
            {
                buf_data = (unsigned char *)vmalloc(mem_sz*1024*1024);
                if (buf_data != NULL)
                {
                    vfree(buf_data);
                    mem_sz = mem_sz + 1;
                    printk("Memory size %dMB allocated!\n", mem_sz);
                }
                else
                {
                    printk("Memory size %dMB failed to allocate\n", mem_sz);
                    break;
                }
            }
*/
            break;
        case UVVP_VDEC_TEST_VERSION_3:
            printk("UVVP_VDEC_TEST_VERSION_3\n");

            buf_data = (unsigned char *)vmalloc(TESTDATA_BUFFER_SZ);
            if (0 == buf_data)
            {
                printk("Allocate %d bytes failed\n", TESTDATA_BUFFER_SZ);
                return 0;
            }

            oldfs = get_fs();
            set_fs(KERNEL_DS); 
#ifdef USB_ACM_DMA1
            printk("UVVP_VDEC_TEST_VERSION_3 Open /dev/usbacm\n");
            fd = filp_open("/dev/usbacm", O_RDWR|O_NOCTTY|O_NDELAY, 0);
            if (fd == 0) 
            {   printk("Open /dev/usbacm failed\n");
                return 0;
            }
#else
            printk("UVVP_VDEC_TEST_VERSION_3 Open /dev/ttyGS0\n");
            fd = filp_open("/dev/ttyGS0", O_RDWR, 0);
            if (fd == 0) 
            {   printk("Open /dev/ttyGS0 failed\n");
                return 0;
            }
            
            fd->f_op->unlocked_ioctl(fd, TCGETS, (unsigned long)&settings);
        
            settings.c_cflag &= ~CBAUD;
            settings.c_cflag |= B921600;

            settings.c_cflag &= ~PARENB;
            settings.c_cflag &= ~CSTOPB;
            settings.c_cflag &= ~CSIZE;
            settings.c_cflag |= CS8 | CLOCAL | CREAD;
            
            settings.c_iflag &= ~(INLCR | ICRNL | IXON | IXOFF | IXANY);
            settings.c_lflag &= ~(ICANON | ECHO | ECHOE | ISIG);  /*raw input*/
            settings.c_oflag &= ~OPOST;  /*raw output*/

            settings.c_cc[VMIN] = 0;
            settings.c_cc[VTIME] = 100;
            
            fd->f_op->unlocked_ioctl(fd, TCSETS, (unsigned long)&settings); 
#endif
            // Read CRC
            printk("Read CRC file\n");
            file_num = remote_open(fd, "Z:\\1280x720_30_2000.ivf.crc", 27, "rb", 2);
            if (file_num < 0)
            {
                printk("Open CRC failed\n");
                return 0;
            }
            file_len = remote_seek(fd, file_num, 0, SEEK_END);
            if (file_len < 0 || file_len > TESTDATA_BUFFER_SZ)
            {
                printk("CRC file too big %d\n", file_len);
                return 0;
            }
            remote_seek(fd, file_num, 0, SEEK_SET);
            read_len = remote_read(fd, file_num, &crc, sizeof(int));
            if (read_len < file_len)
            {
                printk("Fail to read CRC file\n");
                return 0;
            }
            remote_close(fd, file_num);

            // Read real file
            printk("Read Data file\n");
            file_num = remote_open(fd, "Z:\\1280x720_30_2000.ivf", 23, "rb", 2);
            if (file_num < 0)
            {
                printk("Open data file failed\n");
                return 0;
            }
            
            file_len = remote_seek(fd, file_num, 0, SEEK_END);
            if (file_len < 0 || file_len > TESTDATA_BUFFER_SZ)
            {
                printk("Data file too big %d\n", file_len);
                return 0;
            }            
            remote_seek(fd, file_num, 0, SEEK_SET);
            memset(&tv1, 0, sizeof(struct timeval));
            memset(&tv2, 0, sizeof(struct timeval));
            printk("Start reading data\n");
            do_gettimeofday(&tv1);
            read_len = remote_read(fd, file_num, buf_data, file_len);
            do_gettimeofday(&tv2);
            printk("End reading data\n");  
            printk("tv1 %d.%d, tv2 %d.%d \n", tv1.tv_sec, tv1.tv_usec, tv2.tv_sec, tv2.tv_usec);
            tv2.tv_sec -= tv1.tv_sec;
            if (tv2.tv_usec < tv1.tv_usec)
            {
                if (tv2.tv_sec < 1)
                    printk("TIME ERROR\n");
                tv2.tv_usec = tv2.tv_usec + 1000000 - tv1.tv_usec;
                tv2.tv_sec -= 1;
            }
            else
            {
                tv2.tv_usec -= tv1.tv_usec;
            }
            printk("Data len %d, elapsed time %d ms, avg speed %d bytes/ms\n", read_len, (tv2.tv_sec * 1000000 + tv2.tv_usec)/1000, read_len/((tv2.tv_sec * 1000000 + tv2.tv_usec)/1000));
            
            if (read_len < file_len)
            {
                printk("Fail read data file exp. %d, read %d\n", file_len, read_len);
                return 0;
            }
            remote_close(fd, file_num);

            // CRC check
            own_crc = av_adler32_update(1, buf_data, 1, read_len);
            printk("own_crc 0x%08x, crc 0x%08x, %s\n", own_crc, crc, (own_crc == crc) ? "Pass":"******");

            // Write file
            file_num = remote_open(fd, "D:\\Test.txt", 11, "wb", 2);
            if (file_num < 0)
            {
                printk("Open data file failed\n");
                return 0;
            }

            for (i = 0; i < 256; i++)
            {
                tmp_buf[i] = i;
            }
            
            for (i = 0; i < 1024; i++)
            {
                memcpy(buf_data+(1024*i), (unsigned char *)&tmp_buf[0], 1024);
            }

            remote_write(fd, file_num, buf_data, 1024*1024);
            
            remote_close(fd, file_num);            

            filp_close(fd, NULL);
            
            vfree(buf_data);        

	/*
	    _pucVFifo[0] = ioremap(0x8000000, 0x100000);
           memset(_pucVFifo[0] ,5,0x100000);
           printk("_pucVFifo = 0x%x\n", _pucVFifo[0]);
           printk("_pucVFifo m4u_v2p = 0x%x\n", m4u_v2p_new((unsigned int)_pucVFifo[0]));
           iounmap(_pucVFifo[0]);
	    _pucVFifo[0] = ioremap(0x8000000, 0x100000);
           memset(_pucVFifo[0] ,5,0x100000);
           printk("_pucVFifo = 0x%x\n", _pucVFifo[0]);
           printk("_pucVFifo m4u_v2p = 0x%x\n", m4u_v2p_new((unsigned int)_pucVFifo[0]));
           iounmap(_pucVFifo[0]);
	    _pucVFifo[0] = ioremap(0x8000000, 0x100000);
           memset(_pucVFifo[0] ,5,0x100000);
           printk("_pucVFifo = 0x%x\n", _pucVFifo[0]);
           printk("_pucVFifo m4u_v2p = 0x%x\n", m4u_v2p_new((unsigned int)_pucVFifo[0]));
           iounmap(_pucVFifo[0]);
*/
			break;
		case UVVP_VDEC_TEST_VERSION_4:

                  initKernelEnv(); 

                  fd = openFile("/etc/frame_num",O_RDONLY,0); 
                  if (IS_ERR(fd) )
                      printk("[Error] Miss file: input arg file!!!!!!!!!!!!!\n");
                  else
                      readFile(fd ,tmp_buf, 256 );
                  closeFile(fd); 
                  set_fs( oldfs );

                  sscanf ( tmp_buf, "%i %i %i %i %i %s %i %i" , &frame_start, &frame_end, &width, &height, &debug_mode, bitstream_name, &error_rate, &UFO_MODE);

		    hevc_test( frame_start,  frame_end);
		    break;
            
		default:
		    break;

	}
	//printk("\r\n******** uvvp_vdec_ioctl done********\r\n");
	return 0;	
}