From d71d5fc9fd0420d4a738a69c2e68d4e68e31a8fd Mon Sep 17 00:00:00 2001 From: Arun Kumar K Date: Mon, 26 Aug 2013 14:28:28 +0530 Subject: v4l2-mfc-example: Initial support for VP8 parser Added parser code and basic support in application. Signed-off-by: Arun Kumar K Signed-off-by: Mateusz Krawczuk --- v4l2-mfc-example/args.c | 5 +++++ v4l2-mfc-example/parser.c | 37 +++++++++++++++++++++++++++++++++++++ v4l2-mfc-example/parser.h | 4 ++++ 3 files changed, 46 insertions(+) diff --git a/v4l2-mfc-example/args.c b/v4l2-mfc-example/args.c index b121590..3d11694 100644 --- a/v4l2-mfc-example/args.c +++ b/v4l2-mfc-example/args.c @@ -139,6 +139,8 @@ int get_codec(char *str) return V4L2_PIX_FMT_MPEG2; } else if (strncasecmp("mpeg1", str, 5) == 0) { return V4L2_PIX_FMT_MPEG1; + } else if (strncasecmp("vp8", str, 5) == 0) { + return V4L2_PIX_FMT_VP8; } return 0; } @@ -270,6 +272,9 @@ int parse_args(struct instance *i, int argc, char **argv) case V4L2_PIX_FMT_MPEG2: i->parser.func = parse_mpeg2_stream; break; + case V4L2_PIX_FMT_VP8: + i->parser.func = parse_vp8_stream; + break; } return 0; diff --git a/v4l2-mfc-example/parser.c b/v4l2-mfc-example/parser.c index 972cdfc..b4e7f89 100644 --- a/v4l2-mfc-example/parser.c +++ b/v4l2-mfc-example/parser.c @@ -516,3 +516,40 @@ int parse_mpeg2_stream( return frame_finished; } +// IVF is a simple file format that transports raw VP8 data. +int parse_vp8_stream ( + struct mfc_parser_context *ctx, + char* in, int in_size, char* out, int out_size, + int *consumed, int *frame_size, char get_head) +{ + unsigned int index = 0; + unsigned int framesize; + + if ((in[index] == 0x44) && (in[index + 1] == 0x4B) && (in[index + 2] == 0x49) && (in[index + 3] == 0x46)) // 444B4946 : DKIF + { + // IVF header + index += 4; //bytes 0-3 signature: 'DKIF' + index += 2; // plus bytes 4-5 version (should be 0) + index += 2; // plus bytes 6-7 length of header in bytes + index += 4; // plus bytes 8-11 codec FourCC (e.g., 'VP80') + index += 2; // plus bytes 12-13 width in pixels + index += 2; // plus bytes 14-15 height in pixels + index += 4; // plus bytes 16-19 frame rate + index += 4; // plus bytes 20-23 time scale + index += 4; // plus bytes 24-27 number of frames in file + index += 4; // plus bytes 28-31 unused + } + framesize = (in[index + 2] << 16) | (in[index + 1] << 8) | in[index]; + index += 4; //bytes 0-3 size of frame in bytes (not including the 12-byte header) + index += 8; // plus bytes 4-11 64-bit presentation timestamp + + memcpy(out, in + index, framesize); + *frame_size = framesize; + if(get_head==1) + *consumed =0; + else + *consumed = index+framesize; + printf(" frame_size = %d, consumed = %d\n",*frame_size, *consumed); + + return 1; +} diff --git a/v4l2-mfc-example/parser.h b/v4l2-mfc-example/parser.h index 6eea179..16851cc 100644 --- a/v4l2-mfc-example/parser.h +++ b/v4l2-mfc-example/parser.h @@ -91,5 +91,9 @@ int parse_mpeg2_stream(struct mfc_parser_context *ctx, char* in, int in_size, char* out, int out_size, int *consumed, int *frame_size, char get_head); +int parse_vp8_stream(struct mfc_parser_context *ctx, + char* in, int in_size, char* out, int out_size, + int *consumed, int *frame_size, char get_head); + #endif /* PARSER_H_ */ -- cgit v1.2.3