summaryrefslogtreecommitdiff
path: root/pjmedia/src/pjmedia/converter_libyuv.c
blob: 52435d1b3bf7da5870ae99c6861d3f089cd3a31a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
/* $Id$ */
/*
 * Copyright (C) 2010-2011 Teluu Inc. (http://www.teluu.com)
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

#include <pjmedia/converter.h>
#include <pj/errno.h>

#if defined(PJMEDIA_HAS_LIBYUV) && PJMEDIA_HAS_LIBYUV != 0

#include  <libyuv.h>

static pj_status_t factory_create_converter(pjmedia_converter_factory *cf,
					    pj_pool_t *pool,
					    const pjmedia_conversion_param*prm,
					    pjmedia_converter **p_cv);

static void factory_destroy_factory(pjmedia_converter_factory *cf);

static pj_status_t libyuv_conv_convert(pjmedia_converter *converter,
				       pjmedia_frame *src_frame,
				       pjmedia_frame *dst_frame);

static void libyuv_conv_destroy(pjmedia_converter *converter);

static pjmedia_converter_factory_op libyuv_factory_op =
{
    &factory_create_converter,
    &factory_destroy_factory
};

static pjmedia_converter_op libyuv_converter_op =
{
    &libyuv_conv_convert,
    &libyuv_conv_destroy
};

typedef struct fmt_info
{
    const pjmedia_video_format_info 	*vid_fmt_info;
    pjmedia_video_apply_fmt_param 	 apply_param;
} fmt_info;

typedef enum conv_func_type
{
    CONV_PACK_TO_PACK,
    CONV_PACK_TO_PLANAR,
    CONV_PLANAR_TO_PACK,
    CONV_PLANAR_TO_PLANAR,
    SCALE_PACK,
    SCALE_PLANAR
} conv_func_type;

typedef void (*gen_conv_func)();

typedef int (*conv_pack_to_pack_method)(const uint8* src, int src_stride,
					uint8* dst, int dst_stride,
					int width, int height);	

typedef int (*conv_pack_to_planar_method)(const uint8* src, int src_stride,
					  uint8* dst1, int dst_stride1,
					  uint8* dst2, int dst_stride2,
					  uint8* dst3, int dst_stride3,
					  int width, int height);

typedef int (*conv_planar_to_pack_method)(const uint8* src1, int src_stride1,
					  const uint8* src2, int src_stride2,
					  const uint8* src3, int src_stride3,
					  uint8* dst, int dst_stride,
					  int width, int height);

typedef int (*conv_planar_to_planar_method)(const uint8* src1, int src_stride1,
					    const uint8* src2, int src_stride2,
					    const uint8* src3, int src_stride3,
					    uint8* dst1, int dst_stride1,
					    uint8* dst2, int dst_stride2,
					    uint8* dst3, int dst_stride3,
					    int width, int height);

typedef int  (*scale_pack_method)
	     (const uint8* src_argb, int src_stride_argb,
              int src_width, int src_height,
              uint8* dst_argb, int dst_stride_argb,
              int dst_width, int dst_height,
              enum FilterMode filtering);

typedef int (*scale_planar_method)	
	    (const uint8* src_y, int src_stride_y,
             const uint8* src_u, int src_stride_u,
             const uint8* src_v, int src_stride_v,
             int src_width, int src_height,
             uint8* dst_y, int dst_stride_y,
             uint8* dst_u, int dst_stride_u,
             uint8* dst_v, int dst_stride_v,
             int dst_width, int dst_height,
             enum FilterMode filtering);

typedef union act_method
{
    conv_pack_to_pack_method	    conv_pack_to_pack;
    conv_pack_to_planar_method	    conv_pack_to_planar;
    conv_planar_to_pack_method	    conv_planar_to_pack;
    conv_planar_to_planar_method    conv_planar_to_planar;
    scale_pack_method		    scale_pack;
    scale_planar_method		    scale_planar;    
} act_method;

typedef struct fmt_convert_map {
    pj_uint32_t			    src_id;
    pj_uint32_t			    dst_id;
    conv_func_type		    func_type;
    gen_conv_func		    conv_func;
} fmt_convert_map;

/* Maximum number of steps/act needed for the conversion/scale process. */
#define MAXIMUM_ACT 3

/* Define the filter mode for libyuv:
 * 0 : None (fastest)
 * 1 : Linear
 * 2 : Biinear
 * 3 : Filter Box (best quality)
 */
#if !defined(LIBYUV_FILTER_MODE) 
#   define LIBYUV_FILTER_MODE 3
#endif

#define METHOD_IS_SCALE(mtd) mtd>CONV_PLANAR_TO_PLANAR

/* Macro to help define format conversion table. */
#define GET_PJ_FORMAT(fmt) PJMEDIA_FORMAT_##fmt

#define MAP_CONV_PACK_TO_PACK(src,dst,method) GET_PJ_FORMAT(src),\
        GET_PJ_FORMAT(dst),CONV_PACK_TO_PACK,method
#define MAP_CONV_PACK_TO_PLANAR(src,dst,method) GET_PJ_FORMAT(src),\
        GET_PJ_FORMAT(dst),CONV_PACK_TO_PLANAR,method
#define MAP_CONV_PLANAR_TO_PACK(src,dst,method) GET_PJ_FORMAT(src),\
        GET_PJ_FORMAT(dst),CONV_PLANAR_TO_PACK,method
#define MAP_CONV_PLANAR_TO_PLANAR(src,dst,method) GET_PJ_FORMAT(src),\
        GET_PJ_FORMAT(dst),CONV_PLANAR_TO_PLANAR,method
#define MAP_SCALE_PACK(fmt,method) GET_PJ_FORMAT(fmt),\
        GET_PJ_FORMAT(fmt),SCALE_PACK,method
#define MAP_SCALE_PLANAR(fmt,method) GET_PJ_FORMAT(fmt),\
        GET_PJ_FORMAT(fmt),SCALE_PLANAR,method

static fmt_convert_map conv_to_i420[] = 
{
    {MAP_CONV_PACK_TO_PLANAR(RGB24,I420,RGB24ToI420)},
    {MAP_CONV_PACK_TO_PLANAR(RGBA,I420,ABGRToI420)},
    {MAP_CONV_PACK_TO_PLANAR(BGRA,I420,ARGBToI420)},
    {MAP_CONV_PACK_TO_PLANAR(YUY2,I420,YUY2ToI420)},
    {MAP_CONV_PACK_TO_PLANAR(UYVY,I420,UYVYToI420)},
    {MAP_CONV_PLANAR_TO_PLANAR(I422,I420,I422ToI420)}    
};

static fmt_convert_map conv_from_i420[] = 
{
    {MAP_CONV_PLANAR_TO_PACK(I420,RGB24,I420ToRGB24)},
    {MAP_CONV_PLANAR_TO_PACK(I420,RGBA,I420ToABGR)},
    {MAP_CONV_PLANAR_TO_PACK(I420,BGRA,I420ToARGB)},
    {MAP_CONV_PLANAR_TO_PACK(I420,YUY2,I420ToYUY2)},
    {MAP_CONV_PLANAR_TO_PACK(I420,UYVY,I420ToUYVY)},
    {MAP_CONV_PLANAR_TO_PLANAR(I420,I422,I420ToI422)},
    {MAP_SCALE_PLANAR(I420,I420Scale)}
};

static fmt_convert_map conv_to_bgra[] = 
{
    {MAP_CONV_PACK_TO_PACK(RGB24,BGRA,RGB24ToARGB)},
    {MAP_CONV_PACK_TO_PACK(RGBA,BGRA,ABGRToARGB)},    
    {MAP_CONV_PACK_TO_PACK(YUY2,BGRA,YUY2ToARGB)},
    {MAP_CONV_PACK_TO_PACK(UYVY,BGRA,UYVYToARGB)},
    {MAP_CONV_PLANAR_TO_PACK(I422,BGRA,I422ToARGB)},
    {MAP_CONV_PLANAR_TO_PACK(I420,BGRA,I420ToARGB)}
};

static fmt_convert_map conv_from_bgra[] = 
{
    {MAP_CONV_PACK_TO_PACK(BGRA,RGB24,ARGBToRGB24)},
    {MAP_CONV_PACK_TO_PACK(BGRA,RGBA,ARGBToABGR)},
    {MAP_CONV_PACK_TO_PACK(BGRA,YUY2,ARGBToYUY2)},
    {MAP_CONV_PACK_TO_PACK(BGRA,UYVY,ARGBToUYVY)},
    {MAP_CONV_PACK_TO_PLANAR(BGRA,I422,ARGBToI422)},
    {MAP_CONV_PACK_TO_PLANAR(BGRA,I420,ARGBToI420)},
    {MAP_SCALE_PACK(BGRA,ARGBScale)}
};

typedef struct converter_act 
{
    conv_func_type	    act_type;
    struct fmt_info	    src_fmt_info;
    struct fmt_info	    dst_fmt_info;
    act_method		    method;
} converter_act;

struct libyuv_converter
{
    pjmedia_converter 			 base;      
    int					 act_num;
    converter_act			 act[MAXIMUM_ACT];
};

/* Find the matched format conversion map. */ 
static pj_status_t get_converter_map(pj_uint32_t src_id, 
		 		     pj_uint32_t dst_id,
				     const pjmedia_rect_size *src_size, 
				     const pjmedia_rect_size *dst_size,
				     int act_num,
				     converter_act *act)
{
    fmt_convert_map *map = NULL;
    unsigned cnt = 0, i = 0;
    unsigned act_idx = act_num - 1;

#   define GET_MAP(src) \
    do { \
	map=src; \
	cnt=PJ_ARRAY_SIZE(src); \
    }while(0)

    if (src_id == PJMEDIA_FORMAT_I420) {
	GET_MAP(conv_from_i420);
    } else if (src_id == PJMEDIA_FORMAT_BGRA) {
	GET_MAP(conv_from_bgra);
    }

    if (!map) {
	if (dst_id == PJMEDIA_FORMAT_I420) {
	    GET_MAP(conv_to_i420);
	} else if (dst_id == PJMEDIA_FORMAT_BGRA) {
	    GET_MAP(conv_to_bgra);
	}
    }

    if (!map)
	return PJ_ENOTSUP;

    for (;i<cnt;++i) {
	if ((map[i].src_id == src_id) && (map[i].dst_id == dst_id))
	    break;
    }

    if (i == cnt)
	return PJ_ENOTSUP;

    act[act_idx].act_type = map[i].func_type;

    switch (act[act_idx].act_type) {
    case CONV_PACK_TO_PACK:
	act[act_idx].method.conv_pack_to_pack = 
				     (conv_pack_to_pack_method)map[i].conv_func;
	break;
    case CONV_PACK_TO_PLANAR:
	act[act_idx].method.conv_pack_to_planar = 
				   (conv_pack_to_planar_method)map[i].conv_func;
	break;
    case CONV_PLANAR_TO_PACK:
	act[act_idx].method.conv_planar_to_pack = 
				   (conv_planar_to_pack_method)map[i].conv_func;
	break;
    case CONV_PLANAR_TO_PLANAR:
	act[act_idx].method.conv_planar_to_planar = 
				 (conv_planar_to_planar_method)map[i].conv_func;
	break;
    case SCALE_PACK:
	act[act_idx].method.scale_pack = (scale_pack_method)map[i].conv_func;
	break;
    case SCALE_PLANAR:
	act[act_idx].method.scale_planar = 
					  (scale_planar_method)map[i].conv_func;
	break;
    }    

    act[act_idx].src_fmt_info.vid_fmt_info = pjmedia_get_video_format_info(
					    pjmedia_video_format_mgr_instance(),
					    src_id);
    
    act[act_idx].dst_fmt_info.vid_fmt_info = 
	      pjmedia_get_video_format_info(pjmedia_video_format_mgr_instance(),
					    dst_id);

    /* Source buffer size is always the same as the previous destination buffer 
       size, except for the first act. */
    act[act_idx].src_fmt_info.apply_param.size = (!act_idx)?*src_size:
				   act[act_idx-1].dst_fmt_info.apply_param.size;

    /* Destination buffer size is not the same as source buffer size 
       when scaling. */
    act[act_idx].dst_fmt_info.apply_param.size = 
				     (METHOD_IS_SCALE(act[act_idx].act_type))?
				     *dst_size:
				     act[act_idx].src_fmt_info.apply_param.size;
    
    return PJ_SUCCESS;
}

/* This method will return the prefered conversion format based 
 * on the color model. 
 */
static pjmedia_format_id get_next_conv_fmt(pj_uint32_t src_id) {
    const pjmedia_video_format_info *vid_info = pjmedia_get_video_format_info(
					    pjmedia_video_format_mgr_instance(),
					    src_id);

    if (!vid_info)
	return PJMEDIA_FORMAT_BGRA;

    if (vid_info->color_model == PJMEDIA_COLOR_MODEL_YUV) {
	return PJMEDIA_FORMAT_I420;
    } else {
	return PJMEDIA_FORMAT_BGRA;
    }
}

/* This method will find and set all the steps needed for conversion/scale. 
 * More than one step might be needed, since not all format is provided with 
 * a direct conversion/scale method.
 * e.g : Scale YUY2 (240*320) to YUY2 (320*720)
 *	 - Step 1: Convert YUY2(240*320) to I420 (240*320)
 *	 - Step 2: Scale I420 (320*760)
 *	 - Step 3: Convert I420 (320*760) to YUY2 (320*760)
 */
static int set_converter_act(pj_uint32_t src_id, 
			     pj_uint32_t dst_id,
			     const pjmedia_rect_size *src_size, 
			     const pjmedia_rect_size *dst_size,
			     converter_act *act)
{
    unsigned act_num = 0;
    pj_uint32_t current_id = src_id;
    pj_bool_t need_scale = PJ_FALSE;

    /* Convert to I420 or BGRA if needed. */
    if ((src_id != PJMEDIA_FORMAT_I420) || (src_id != PJMEDIA_FORMAT_BGRA)) {
	pj_uint32_t next_id = get_next_conv_fmt(src_id);
        if (get_converter_map(src_id, next_id, src_size, dst_size, ++act_num, 
                              act) != PJ_SUCCESS)
        {
            return 0;			
        }						   
        	
	current_id = next_id;
    }

    /* Scale if needed */
    need_scale = ((src_size->w != dst_size->w) ||
		  (src_size->h != dst_size->h));

    if (need_scale) {
	if (get_converter_map(current_id, current_id, src_size, dst_size, 
			      ++act_num, act) != PJ_SUCCESS)
        {
            return 0;                        
        }                              
    }

    /* Convert if needed */
    if (current_id != dst_id) {
	if (get_converter_map(current_id, dst_id, src_size, dst_size, ++act_num,
                              act) != PJ_SUCCESS)
        {
            return 0;
        }                              
    }

    return act_num; 
}

/* Additional buffer might be needed for formats without direct conversion/scale
 * method. This method will allocate and set the destination buffer needed by
 * the conversion/scaling process.
 */
static pj_status_t set_destination_buffer(pj_pool_t *pool, 
					  struct libyuv_converter *lconv)
{
    int i = 0;

    for (;i<lconv->act_num-1;++i) {
	pj_size_t buffer_size = 0;	
	fmt_info *info = &lconv->act[i].dst_fmt_info;

	/* Get destination buffer size. */
	(*info->vid_fmt_info->apply_fmt)(info->vid_fmt_info, 
					 &info->apply_param);

	buffer_size = info->apply_param.framebytes;

	/* Allocate buffer. */
	lconv->act[i].dst_fmt_info.apply_param.buffer = 
				  (pj_uint8_t*)pj_pool_alloc(pool, buffer_size);

	if (!lconv->act[i].dst_fmt_info.apply_param.buffer)
	    return PJ_ENOMEM;
    }
    return PJ_SUCCESS;
}

/* Check the act input/output format matched the conversion/scale format. */
static pj_bool_t check_converter_act(const converter_act *act, 
				     int act_num, 
				     pj_uint32_t src_id,
				     const pjmedia_rect_size *src_size,
				     pj_uint32_t dst_id, 
				     const pjmedia_rect_size *dst_size)
{
    if (act_num) {
	const struct fmt_info *first_fmt = &act[0].src_fmt_info;
	const struct fmt_info *last_fmt = &act[act_num-1].dst_fmt_info;	

	if ((first_fmt->vid_fmt_info->id == src_id) &&
	    (first_fmt->apply_param.size.h == src_size->h) &&
	    (first_fmt->apply_param.size.w == src_size->w) &&
	    (last_fmt->vid_fmt_info->id == dst_id) && 
	    (last_fmt->apply_param.size.h == dst_size->h) &&
	    (last_fmt->apply_param.size.w == dst_size->w))
	{
	    return PJ_TRUE;
	}
    } 
    return PJ_FALSE;
}

static pj_status_t factory_create_converter(pjmedia_converter_factory *cf,
					    pj_pool_t *pool,
					    const pjmedia_conversion_param *prm,
					    pjmedia_converter **p_cv)
{
    const pjmedia_video_format_detail *src_detail, *dst_detail;
    const pjmedia_video_format_info *src_fmt_info, *dst_fmt_info;
    struct libyuv_converter *lconv = NULL;
    pj_status_t status = PJ_ENOTSUP;

    PJ_UNUSED_ARG(cf);

    /* Only supports video */
    if (prm->src.type != PJMEDIA_TYPE_VIDEO ||
	prm->dst.type != prm->src.type ||
	prm->src.detail_type != PJMEDIA_FORMAT_DETAIL_VIDEO ||
	prm->dst.detail_type != prm->src.detail_type)
    {
	return status;
    }

    /* lookup source format info */
    src_fmt_info = pjmedia_get_video_format_info(
					    pjmedia_video_format_mgr_instance(),
					    prm->src.id);

    if (!src_fmt_info)
	return status;

    /* lookup destination format info */
    dst_fmt_info = pjmedia_get_video_format_info(
					    pjmedia_video_format_mgr_instance(),
					    prm->dst.id);

    if (!dst_fmt_info)
	return status;

    src_detail = pjmedia_format_get_video_format_detail(&prm->src, PJ_TRUE);
    dst_detail = pjmedia_format_get_video_format_detail(&prm->dst, PJ_TRUE);
    
    lconv = PJ_POOL_ZALLOC_T(pool, struct libyuv_converter);
    lconv->base.op = &libyuv_converter_op;

    lconv->act_num = set_converter_act(src_fmt_info->id, dst_fmt_info->id, 
				       &src_detail->size, &dst_detail->size,
				       lconv->act);

    if (!lconv->act_num) {
	return status;
    }

    if (!check_converter_act(lconv->act, lconv->act_num, 
			     src_fmt_info->id, &src_detail->size,
			     dst_fmt_info->id, &dst_detail->size)) 
    {
	return status;
    }

    status = set_destination_buffer(pool, lconv);

    *p_cv = &lconv->base;

    return status;
}

static void factory_destroy_factory(pjmedia_converter_factory *cf)
{
    PJ_UNUSED_ARG(cf);
}

static pj_status_t libyuv_conv_convert(pjmedia_converter *converter,
				       pjmedia_frame *src_frame,
				       pjmedia_frame *dst_frame)
{
    struct libyuv_converter *lconv = (struct libyuv_converter*)converter;
    int i = 0;

    /* Set the first act buffer from src frame. */
    lconv->act[0].src_fmt_info.apply_param.buffer = src_frame->buf;

    /* Set the last act buffer from dst frame. */
    lconv->act[lconv->act_num-1].dst_fmt_info.apply_param.buffer = 
								 dst_frame->buf;

    for (;i<lconv->act_num;++i) {	
	/* Use destination info as the source info for the next act. */
	struct fmt_info *src_fmt_info = (i==0)?&lconv->act[i].src_fmt_info: 
					&lconv->act[i-1].dst_fmt_info;

	struct fmt_info *dst_fmt_info = &lconv->act[i].dst_fmt_info;	
	
	(*src_fmt_info->vid_fmt_info->apply_fmt)(src_fmt_info->vid_fmt_info, 
						 &src_fmt_info->apply_param);

	(*dst_fmt_info->vid_fmt_info->apply_fmt)(dst_fmt_info->vid_fmt_info, 
						 &dst_fmt_info->apply_param);

	switch (lconv->act[i].act_type) {
	case CONV_PACK_TO_PACK:
	    (*lconv->act[i].method.conv_pack_to_pack)(
			      (const uint8*)src_fmt_info->apply_param.planes[0],
			      src_fmt_info->apply_param.strides[0],
			      dst_fmt_info->apply_param.planes[0], 
			      dst_fmt_info->apply_param.strides[0],
			      dst_fmt_info->apply_param.size.w, 
			      dst_fmt_info->apply_param.size.h);
	    break;
	case CONV_PACK_TO_PLANAR:
	    (*lconv->act[i].method.conv_pack_to_planar)(
			      (const uint8*)src_fmt_info->apply_param.planes[0],
			      src_fmt_info->apply_param.strides[0],
			      dst_fmt_info->apply_param.planes[0], 
			      dst_fmt_info->apply_param.strides[0],
			      dst_fmt_info->apply_param.planes[1], 
			      dst_fmt_info->apply_param.strides[1],
			      dst_fmt_info->apply_param.planes[2], 
			      dst_fmt_info->apply_param.strides[2],
			      dst_fmt_info->apply_param.size.w, 
			      dst_fmt_info->apply_param.size.h);
	    break;
	case CONV_PLANAR_TO_PACK:
	    (*lconv->act[i].method.conv_planar_to_pack)(
			      (const uint8*)src_fmt_info->apply_param.planes[0],
			      src_fmt_info->apply_param.strides[0],
			      (const uint8*)src_fmt_info->apply_param.planes[1],
			      src_fmt_info->apply_param.strides[1],
			      (const uint8*)src_fmt_info->apply_param.planes[2],
			      src_fmt_info->apply_param.strides[2],
			      dst_fmt_info->apply_param.planes[0], 
			      dst_fmt_info->apply_param.strides[0],
			      dst_fmt_info->apply_param.size.w, 
			      dst_fmt_info->apply_param.size.h);
	    break;
	case CONV_PLANAR_TO_PLANAR:
	    (*lconv->act[i].method.conv_planar_to_planar)(
			      (const uint8*)src_fmt_info->apply_param.planes[0],
			      src_fmt_info->apply_param.strides[0],
			      (const uint8*)src_fmt_info->apply_param.planes[1],
			      src_fmt_info->apply_param.strides[1],
			      (const uint8*)src_fmt_info->apply_param.planes[2],
			      src_fmt_info->apply_param.strides[2],
			      dst_fmt_info->apply_param.planes[0], 
			      dst_fmt_info->apply_param.strides[0],
			      dst_fmt_info->apply_param.planes[1], 
			      dst_fmt_info->apply_param.strides[1],
			      dst_fmt_info->apply_param.planes[2], 
			      dst_fmt_info->apply_param.strides[2],
			      dst_fmt_info->apply_param.size.w, 
			      dst_fmt_info->apply_param.size.h);
	    break;
	case SCALE_PACK:
	    (*lconv->act[i].method.scale_pack)(
			      (const uint8*)src_fmt_info->apply_param.planes[0],
			      src_fmt_info->apply_param.strides[0],
			      src_fmt_info->apply_param.size.w,
			      src_fmt_info->apply_param.size.h,
			      (uint8*)dst_fmt_info->apply_param.planes[0],
			      dst_fmt_info->apply_param.strides[0],
			      dst_fmt_info->apply_param.size.w,
			      dst_fmt_info->apply_param.size.h,
			      LIBYUV_FILTER_MODE);
	    break;	
	case SCALE_PLANAR:
	    (*lconv->act[i].method.scale_planar)(
			      (const uint8*)src_fmt_info->apply_param.planes[0],
			      src_fmt_info->apply_param.strides[0],
			      (const uint8*)src_fmt_info->apply_param.planes[1],
			      src_fmt_info->apply_param.strides[1],
			      (const uint8*)src_fmt_info->apply_param.planes[2],
			      src_fmt_info->apply_param.strides[2],
			      src_fmt_info->apply_param.size.w,
			      src_fmt_info->apply_param.size.h,
			      (uint8*)dst_fmt_info->apply_param.planes[0],
			      dst_fmt_info->apply_param.strides[0],
			      (uint8*)dst_fmt_info->apply_param.planes[1],
			      dst_fmt_info->apply_param.strides[1],
			      (uint8*)dst_fmt_info->apply_param.planes[2],
			      dst_fmt_info->apply_param.strides[2],
			      dst_fmt_info->apply_param.size.w,
			      dst_fmt_info->apply_param.size.h,
			      LIBYUV_FILTER_MODE);
	    break;	
	};	
    }    
    return PJ_SUCCESS;
}

static void libyuv_conv_destroy(pjmedia_converter *converter)
{
    PJ_UNUSED_ARG(converter);
}

static pjmedia_converter_factory libyuv_factory =
{
    NULL, NULL,					/* list */
    "libyuv",					/* name */
    PJMEDIA_CONVERTER_PRIORITY_NORMAL,		/* priority */
    NULL					/* op will be init-ed later  */
};

PJ_DEF(pj_status_t)
pjmedia_libyuv_converter_init(pjmedia_converter_mgr *mgr)
{
    libyuv_factory.op = &libyuv_factory_op;
    return pjmedia_converter_mgr_register_factory(mgr, &libyuv_factory);
}


PJ_DEF(pj_status_t)
pjmedia_libyuv_converter_shutdown(pjmedia_converter_mgr *mgr,
				  pj_pool_t *pool)
{
    PJ_UNUSED_ARG(pool);
    return pjmedia_converter_mgr_unregister_factory(mgr, &libyuv_factory,
						    PJ_TRUE);
}

#ifdef _MSC_VER
#   pragma comment(lib, "libyuv.lib")
#endif

#endif //#if defined(PJMEDIA_HAS_LIBYUV) && PJMEDIA_HAS_LIBYUV != 0