|
Home --> Documentations --> PJMEDIA Reference
Video codec encode and decode test.
This file is pjsip-apps/src/samples/vid_codec_test.c
31#include <pjlib-util.h>
36#if defined(PJMEDIA_HAS_VIDEO) && (PJMEDIA_HAS_VIDEO != 0)
45#define THIS_FILE "vid_vodec_test.c"
49#define HAS_LOCAL_RENDERER_FOR_PLAY_FILE 1
55#define DEF_RENDERER_WIDTH 640
56#define DEF_RENDERER_HEIGHT 480
60int hex_string_to_octet_string( char *raw, char *hex, int len);
72#if defined(PJMEDIA_HAS_OPENH264_CODEC) && PJMEDIA_HAS_OPENH264_CODEC != 0
77#if defined(PJMEDIA_HAS_VID_TOOLBOX_CODEC) && \
78 PJMEDIA_HAS_VID_TOOLBOX_CODEC != 0
83#if defined(PJMEDIA_HAS_VPX_CODEC) && PJMEDIA_HAS_VPX_CODEC != 0
88#if defined(PJMEDIA_HAS_FFMPEG_VID_CODEC) && PJMEDIA_HAS_FFMPEG_VID_CODEC != 0
99static void deinit_codecs()
101#if defined(PJMEDIA_HAS_FFMPEG_VID_CODEC) && PJMEDIA_HAS_FFMPEG_VID_CODEC != 0
105#if defined(PJMEDIA_HAS_OPENH264_CODEC) && PJMEDIA_HAS_OPENH264_CODEC != 0
109#if defined(PJMEDIA_HAS_VID_TOOLBOX_CODEC) && \
110 PJMEDIA_HAS_VID_TOOLBOX_CODEC != 0
114#if defined(PJMEDIA_HAS_VPX_CODEC) && PJMEDIA_HAS_VPX_CODEC != 0
130 const pj_uint8_t *p1 = buf1 + i, *p2 = buf2 + i;
134 for (j=0; j<STEP && i+j<size; ++j) {
135 printf( " %02x", *(p1+j));
139 for (j=0; j<STEP && i+j<size; ++j) {
140 if (*(p1+j) == *(p2+j)) {
141 printf( " %02x", *(p2+j));
143 printf( " %02x", *(p2+j));
152static void diff_file()
154 const char *filename[2] = {
155 "/home/bennylp/Desktop/opt/src/openh264-svn/testbin/test.264",
156 "/home/bennylp/Desktop/opt/src/openh264-svn/testbin/test2.264"
160 unsigned i, pos[2], frame_cnt, mismatch_cnt=0;
162 for (i=0; i<2; ++i) {
166 fhnd = fopen(filename[i], "rb");
168 printf( "Error opening %s\n", filename[i]);
172 fseek(fhnd, 0, SEEK_END);
173 size[i] = ftell(fhnd);
174 fseek(fhnd, 0, SEEK_SET);
182 if (fread (buf[i], 1, size[i], fhnd) != ( unsigned)size[i]) {
183 fprintf (stderr, "Unable to read whole file\n");
188 memcpy (buf[i] + size[i], start_nal, sizeof(start_nal));
193 if (size[0] != size[1]) {
194 printf( "File size mismatch\n");
199 for ( frame_cnt=0; ; ++frame_cnt) {
201 for (i = 0; i < size[0]; i++) {
202 if (memcmp(buf[0] + pos[0] + i, start_nal,
203 sizeof(start_nal)) == 0 && i > 0)
209 for (i = 0; i < size[1]; i++) {
210 if (memcmp(buf[1] + pos[1] + i, start_nal,
211 sizeof(start_nal)) == 0 && i > 0)
218 if (nal_len[0] != nal_len[1]) {
219 printf( "Different size in frame %d (%d vs %d)\n",
220 frame_cnt, nal_len[0], nal_len[1]);
223 if (memcmp(buf[0]+pos[0], buf[1]+pos[1], nal_len[0]) != 0) {
224 printf( "Mismatch in frame %d\n", frame_cnt);
225 show_diff(buf[0]+pos[0], buf[1]+pos[1], nal_len[0]);
230 pos[0] += nal_len[0];
231 pos[1] += nal_len[1];
233 if (pos[0] >= size[0])
241 puts( "Files the same!");
243 printf( "%d mismatches\n", mismatch_cnt);
249int main( int argc, char *argv[])
257 char *codec_id = ( char*) "H264";
264 const char *save_filename = NULL;
272 YUV_SIZE = WIDTH * HEIGHT * 3 >> 1,
273 YUV_BUF_SIZE = YUV_SIZE + WIDTH,
281 enc_buf_type enc_buf[MAX_FRAMES];
282 unsigned read_cnt = 0,
324 status = init_codecs(&cp. factory);
328 fyuv = fopen( "pjsip-apps/bin/CiscoVT2people_320x192_12fps.yuv", "rb");
330 puts( "Unable to open ../CiscoVT2people_320x192_12fps.yuv");
337 f264 = fopen(save_filename, "wb");
346 &str_codec_id, &count,
349 printf( "Error: unable to find codec %s\n", codec_id);
358 codec_info = &info[0];
369 PJ_PERROR(3,(THIS_FILE, status, "Error allocating codec"));
383 PJ_PERROR(3,(THIS_FILE, status, "Error initializing codec"));
389 PJ_PERROR(3,(THIS_FILE, status, "Error opening codec"));
393 while (fread(yuv_frame, 1, YUV_SIZE, fyuv) == YUV_SIZE) {
400 pj_bzero(&frm_enc, sizeof(frm_enc));
401 pj_bzero(&frm_yuv, sizeof(frm_yuv));
403 frm_yuv. buf = yuv_frame;
404 frm_yuv. size = YUV_SIZE;
407 frm_enc[enc_cnt]. buf = enc_buf[enc_cnt];
408 frm_enc[enc_cnt]. size = MTU;
411 MTU, &frm_enc[enc_cnt],
414 PJ_PERROR(3,(THIS_FILE, status, "Codec encode error"));
417 if (frm_enc[enc_cnt].size) {
419 fwrite(start_nal, 1, sizeof(start_nal), f264);
420 fwrite(frm_enc[enc_cnt].buf, 1, frm_enc[enc_cnt].size, f264);
428 if (enc_cnt >= MAX_FRAMES) {
430 puts( "Error: too many encoded frames");
435 frm_enc[enc_cnt]. buf = enc_buf[enc_cnt];
436 frm_enc[enc_cnt]. size = MTU;
442 PJ_PERROR(3,(THIS_FILE, status, "Codec encode error"));
446 if (frm_enc[enc_cnt].size) {
448 fwrite(start_nal, 1, sizeof(start_nal), f264);
449 fwrite(frm_enc[enc_cnt].buf, 1, frm_enc[enc_cnt].size,
458 frm_yuv. buf = yuv_frame;
459 frm_yuv. size = YUV_BUF_SIZE;
465 PJ_PERROR(3,(THIS_FILE, status, "Codec decode error"));
469 if (frm_yuv. size != 0) {
476 " Read YUV frames: %d\n"
477 " Encoded packets: %d\n"
478 " Decoded YUV frames: %d\n",
479 read_cnt, pkt_cnt, dec_cnt);
521int main( int argc, char *argv[])
525 puts( "Error: this sample requires video capability "
526 "(PJMEDIA_HAS_VIDEO == 1)");
pj_status_t pjmedia_endpt_create(pj_pool_factory *pf, pj_ioqueue_t *ioqueue, unsigned worker_cnt, pjmedia_endpt **p_endpt) Definition: endpoint.h:127
pj_status_t pjmedia_endpt_destroy(pjmedia_endpt *endpt) Definition: endpoint.h:168
pj_status_t pj_init(void)
void pj_caching_pool_destroy(pj_caching_pool *ch_pool)
void pj_caching_pool_init(pj_caching_pool *ch_pool, const pj_pool_factory_policy *policy, pj_size_t max_capacity)
pj_pool_factory_policy pj_pool_factory_default_policy
pj_pool_t * pj_pool_create(pj_pool_factory *factory, const char *name, pj_size_t initial_size, pj_size_t increment_size, pj_pool_callback *callback)
void pj_pool_release(pj_pool_t *pool)
pj_str_t pj_str(char *str)
void pj_bzero(void *dst, pj_size_t size)
#define PJ_ASSERT_RETURN(expr, retval)
#define PJ_UNUSED_ARG(arg)
#define PJ_PERROR(level, arg)
PJMEDIA small footprint Open Source media stack
Copyright (C) 2006-2008 Teluu Inc.
|