Coverage Report

Created: 2025-08-28 07:07

/src/pjsip/pjmedia/include/pjmedia/vid_codec.h
Line
Count
Source (jump to first uncovered line)
1
/* 
2
 * Copyright (C) 2008-2011 Teluu Inc. (http://www.teluu.com)
3
 * Copyright (C) 2003-2008 Benny Prijono <benny@prijono.org>
4
 *
5
 * This program is free software; you can redistribute it and/or modify
6
 * it under the terms of the GNU General Public License as published by
7
 * the Free Software Foundation; either version 2 of the License, or
8
 * (at your option) any later version.
9
 *
10
 * This program is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 * GNU General Public License for more details.
14
 *
15
 * You should have received a copy of the GNU General Public License
16
 * along with this program; if not, write to the Free Software
17
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA 
18
 */
19
#ifndef __PJMEDIA_VID_CODEC_H__
20
#define __PJMEDIA_VID_CODEC_H__
21
22
23
/**
24
 * @file vid_codec.h
25
 * @brief Video codec framework.
26
 */
27
28
#include <pjmedia/codec.h>
29
#include <pjmedia/event.h>
30
#include <pjmedia/format.h>
31
#include <pjmedia/types.h>
32
#include <pj/list.h>
33
#include <pj/pool.h>
34
35
PJ_BEGIN_DECL
36
37
/**
38
 * @defgroup PJMEDIA_VID_CODEC Video Codecs
39
 * @ingroup PJMEDIA_CODEC
40
 * @{
41
 */
42
43
#define PJMEDIA_VID_CODEC_MAX_DEC_FMT_CNT    8
44
#define PJMEDIA_VID_CODEC_MAX_FPS_CNT        16
45
46
/**
47
 * This enumeration specifies the packetization property of video encoding
48
 * process. The value is bitmask, and smaller value will have higher priority
49
 * to be used.
50
 */
51
typedef enum pjmedia_vid_packing
52
{
53
    /**
54
     * This specifies that the packetization is unknown, or if nothing
55
     * is supported.
56
     */
57
    PJMEDIA_VID_PACKING_UNKNOWN,
58
59
    /**
60
     * This specifies that the result of video encoding process will be
61
     * segmented into packets, which is suitable for RTP transmission.
62
     * The maximum size of the packets is set in \a enc_mtu field of
63
     * pjmedia_vid_codec_param.
64
     */
65
    PJMEDIA_VID_PACKING_PACKETS = 1,
66
67
    /**
68
     * This specifies that video encoding function will produce a whole
69
     * or full frame from the source frame. This is normally used for
70
     * encoding video for offline storage such as to an AVI file. The
71
     * maximum size of the packets is set in \a enc_mtu field of
72
     * pjmedia_vid_codec_param.
73
     */
74
    PJMEDIA_VID_PACKING_WHOLE = 2
75
76
} pjmedia_vid_packing;
77
78
79
/**
80
 * Enumeration of video frame info flag for the bit_info field in the
81
 * pjmedia_frame.
82
 */
83
typedef enum pjmedia_vid_frm_bit_info
84
{
85
    /**
86
     * The video frame is keyframe.
87
     */
88
    PJMEDIA_VID_FRM_KEYFRAME    = 1
89
90
} pjmedia_vid_frm_bit_info;
91
92
93
/**
94
 * Encoding option.
95
 */
96
typedef struct pjmedia_vid_encode_opt
97
{
98
    /**
99
     * Flag to force the encoder to generate keyframe for the specified input
100
     * frame. When this flag is set, application can verify the result by
101
     * examining PJMEDIA_VID_FRM_KEYFRAME flag in the bit_info field of the
102
     * output frame.
103
     */
104
    pj_bool_t force_keyframe;
105
106
} pjmedia_vid_encode_opt;
107
108
109
/** 
110
 * Identification used to search for codec factory that supports specific 
111
 * codec specification. 
112
 */
113
typedef struct pjmedia_vid_codec_info
114
{
115
    pjmedia_format_id   fmt_id;         /**< Encoded format ID              */
116
    unsigned            pt;             /**< Payload type                   */
117
    pj_str_t            encoding_name;  /**< Encoding name                  */
118
    pj_str_t            encoding_desc;  /**< Encoding desc                  */
119
    unsigned            clock_rate;     /**< Clock rate                     */
120
    pjmedia_dir         dir;            /**< Direction                      */
121
    unsigned            dec_fmt_id_cnt; /**< # of supported encoding source 
122
                                             format IDs                     */
123
    pjmedia_format_id   dec_fmt_id[PJMEDIA_VID_CODEC_MAX_DEC_FMT_CNT];
124
                                        /**< Supported encoding source 
125
                                             format IDs                     */
126
    unsigned            packings;       /**< Supported or requested packings,
127
                                             strategies, bitmask from
128
                                             pjmedia_vid_packing            */
129
    unsigned            fps_cnt;        /**< # of supported frame-rates, can be
130
                                             zero (support any frame-rate)  */
131
    pjmedia_ratio       fps[PJMEDIA_VID_CODEC_MAX_FPS_CNT];
132
                                        /**< Supported frame-rates          */
133
134
} pjmedia_vid_codec_info;
135
136
137
/** 
138
 * Detailed codec attributes used in configuring a codec and in querying
139
 * the capability of codec factories. Default attributes of any codecs could
140
 * be queried using #pjmedia_vid_codec_mgr_get_default_param() and modified
141
 * using #pjmedia_vid_codec_mgr_set_default_param().
142
 *
143
 * Please note that codec parameter also contains SDP specific setting, 
144
 * #dec_fmtp and #enc_fmtp, which may need to be set appropriately based on
145
 * the effective setting. See each codec documentation for more detail.
146
 */
147
typedef struct pjmedia_vid_codec_param
148
{
149
    pjmedia_dir         dir;            /**< Direction                      */
150
    pjmedia_vid_packing packing;        /**< Packetization strategy.        */
151
152
    pjmedia_format      enc_fmt;        /**< Encoded format                 */
153
    pjmedia_codec_fmtp  enc_fmtp;       /**< Encoder fmtp params            */
154
    unsigned            enc_mtu;        /**< MTU or max payload size setting*/
155
156
    pjmedia_format      dec_fmt;        /**< Decoded format                 */
157
    pjmedia_codec_fmtp  dec_fmtp;       /**< Decoder fmtp params            */
158
159
    pj_bool_t           ignore_fmtp;    /**< Ignore fmtp params. If set to
160
                                             PJ_TRUE, the codec will apply
161
                                             format settings specified in
162
                                             enc_fmt and dec_fmt only.      */
163
164
} pjmedia_vid_codec_param;
165
166
167
/**
168
 * Duplicate video codec parameter.
169
 *
170
 * @param pool      The pool.
171
 * @param src       The video codec parameter to be duplicated.
172
 *
173
 * @return          Duplicated codec parameter.
174
 */
175
PJ_DECL(pjmedia_vid_codec_param*) pjmedia_vid_codec_param_clone(
176
                                        pj_pool_t *pool, 
177
                                        const pjmedia_vid_codec_param *src);
178
179
/**
180
 * Forward declaration for video codec.
181
 */
182
typedef struct pjmedia_vid_codec pjmedia_vid_codec;
183
184
185
/**
186
 * This structure describes codec operations. Each codec MUST implement
187
 * all of these functions.
188
 */
189
typedef struct pjmedia_vid_codec_op
190
{
191
    /** 
192
     * See #pjmedia_vid_codec_init().
193
     */
194
    pj_status_t (*init)(pjmedia_vid_codec *codec, 
195
                        pj_pool_t *pool );
196
197
    /** 
198
     * See #pjmedia_vid_codec_open().
199
     */
200
    pj_status_t (*open)(pjmedia_vid_codec *codec, 
201
                        pjmedia_vid_codec_param *param );
202
203
    /** 
204
     * See #pjmedia_vid_codec_close().
205
     */
206
    pj_status_t (*close)(pjmedia_vid_codec *codec);
207
208
    /** 
209
     * See #pjmedia_vid_codec_modify().
210
     */
211
    pj_status_t (*modify)(pjmedia_vid_codec *codec,
212
                          const pjmedia_vid_codec_param *param);
213
214
    /** 
215
     * See #pjmedia_vid_codec_get_param().
216
     */
217
    pj_status_t (*get_param)(pjmedia_vid_codec *codec,
218
                             pjmedia_vid_codec_param *param);
219
220
    /**
221
     * See #pjmedia_vid_codec_encode_begin().
222
     */
223
    pj_status_t (*encode_begin)(pjmedia_vid_codec *codec,
224
                                const pjmedia_vid_encode_opt *opt,
225
                                const pjmedia_frame *input,
226
                                unsigned out_size,
227
                                pjmedia_frame *output,
228
                                pj_bool_t *has_more);
229
230
    /**
231
     * See #pjmedia_vid_codec_encode_more()
232
     */
233
    pj_status_t (*encode_more)(pjmedia_vid_codec *codec,
234
                               unsigned out_size,
235
                               pjmedia_frame *output,
236
                               pj_bool_t *has_more);
237
238
239
    /*
240
     * See #pjmedia_vid_codec_decode().
241
     */
242
    pj_status_t (*decode)(pjmedia_vid_codec *codec,
243
                          pj_size_t count,
244
                          pjmedia_frame packets[],
245
                          unsigned out_size,
246
                          pjmedia_frame *output);
247
248
    /**
249
     * See #pjmedia_vid_codec_recover()
250
     */
251
    pj_status_t (*recover)(pjmedia_vid_codec *codec,
252
                           unsigned out_size,
253
                           pjmedia_frame *output);
254
255
} pjmedia_vid_codec_op;
256
257
258
259
/*
260
 * Forward declaration for pjmedia_vid_codec_factory.
261
 */
262
typedef struct pjmedia_vid_codec_factory pjmedia_vid_codec_factory;
263
264
265
/**
266
 * This structure describes a video codec instance. Codec implementers
267
 * should use #pjmedia_vid_codec_init() to initialize this structure with
268
 * default values.
269
 */
270
struct pjmedia_vid_codec
271
{
272
    /** Entries to put this codec instance in codec factory's list. */
273
    PJ_DECL_LIST_MEMBER(struct pjmedia_vid_codec);
274
275
    /** Codec's private data. */
276
    void                        *codec_data;
277
278
    /** Codec factory where this codec was allocated. */
279
    pjmedia_vid_codec_factory   *factory;
280
281
    /** Operations to codec. */
282
    pjmedia_vid_codec_op        *op;
283
};
284
285
286
287
/**
288
 * This structure describes operations that must be supported by codec 
289
 * factories.
290
 */
291
typedef struct pjmedia_vid_codec_factory_op
292
{
293
    /** 
294
     * Check whether the factory can create codec with the specified 
295
     * codec info.
296
     *
297
     * @param factory   The codec factory.
298
     * @param info      The codec info.
299
     *
300
     * @return          PJ_SUCCESS if this factory is able to create an
301
     *                  instance of codec with the specified info.
302
     */
303
    pj_status_t (*test_alloc)(pjmedia_vid_codec_factory *factory, 
304
                              const pjmedia_vid_codec_info *info );
305
306
    /** 
307
     * Create default attributes for the specified codec ID. This function
308
     * can be called by application to get the capability of the codec.
309
     *
310
     * @param factory   The codec factory.
311
     * @param info      The codec info.
312
     * @param attr      The attribute to be initialized.
313
     *
314
     * @return          PJ_SUCCESS if success.
315
     */
316
    pj_status_t (*default_attr)(pjmedia_vid_codec_factory *factory, 
317
                                const pjmedia_vid_codec_info *info,
318
                                pjmedia_vid_codec_param *attr );
319
320
    /** 
321
     * Enumerate supported codecs that can be created using this factory.
322
     * 
323
     *  @param factory  The codec factory.
324
     *  @param count    On input, specifies the number of elements in
325
     *                  the array. On output, the value will be set to
326
     *                  the number of elements that have been initialized
327
     *                  by this function.
328
     *  @param info     The codec info array, which contents will be 
329
     *                  initialized upon return.
330
     *
331
     *  @return         PJ_SUCCESS on success.
332
     */
333
    pj_status_t (*enum_info)(pjmedia_vid_codec_factory *factory, 
334
                             unsigned *count, 
335
                             pjmedia_vid_codec_info codecs[]);
336
337
    /** 
338
     * Create one instance of the codec with the specified codec info.
339
     *
340
     * @param factory   The codec factory.
341
     * @param info      The codec info.
342
     * @param p_codec   Pointer to receive the codec instance.
343
     *
344
     * @return          PJ_SUCCESS on success.
345
     */
346
    pj_status_t (*alloc_codec)(pjmedia_vid_codec_factory *factory, 
347
                               const pjmedia_vid_codec_info *info,
348
                               pjmedia_vid_codec **p_codec);
349
350
    /** 
351
     * This function is called by codec manager to return a particular 
352
     * instance of codec back to the codec factory.
353
     *
354
     * @param factory   The codec factory.
355
     * @param codec     The codec instance to be returned.
356
     *
357
     * @return          PJ_SUCCESS on success.
358
     */
359
    pj_status_t (*dealloc_codec)(pjmedia_vid_codec_factory *factory, 
360
                                 pjmedia_vid_codec *codec );
361
362
} pjmedia_vid_codec_factory_op;
363
364
365
366
/**
367
 * Codec factory describes a module that is able to create codec with specific
368
 * capabilities. These capabilities can be queried by codec manager to create
369
 * instances of codec.
370
 */
371
struct pjmedia_vid_codec_factory
372
{
373
    /** Entries to put this structure in the codec manager list. */
374
    PJ_DECL_LIST_MEMBER(struct pjmedia_vid_codec_factory);
375
376
    /** The factory's private data. */
377
    void                     *factory_data;
378
379
    /** Operations to the factory. */
380
    pjmedia_vid_codec_factory_op *op;
381
382
};
383
384
385
/**
386
 * Opaque declaration for codec manager.
387
 */
388
typedef struct pjmedia_vid_codec_mgr pjmedia_vid_codec_mgr;
389
390
/**
391
 * Declare maximum codecs
392
 */
393
#define PJMEDIA_VID_CODEC_MGR_MAX_CODECS            32
394
395
396
/**
397
 * Initialize codec manager. If there is no the default video codec manager,
398
 * this function will automatically set the default video codec manager to
399
 * the new codec manager instance. Normally this function is called by pjmedia
400
 * endpoint's initialization code.
401
 *
402
 * @param pool      The pool instance.
403
 * @param mgr       The pointer to the new codec manager instance.
404
 *
405
 * @return          PJ_SUCCESS on success.
406
 */
407
PJ_DECL(pj_status_t) pjmedia_vid_codec_mgr_create(pj_pool_t *pool,
408
                                                  pjmedia_vid_codec_mgr **mgr);
409
410
411
/**
412
 * Destroy codec manager. Normally this function is called by pjmedia
413
 * endpoint's deinitialization code.
414
 *
415
 * @param mgr       Codec manager instance.  If NULL, it is the default codec
416
 *                  manager instance will be destroyed.
417
 *
418
 * @return          PJ_SUCCESS on success.
419
 */
420
PJ_DECL(pj_status_t) pjmedia_vid_codec_mgr_destroy(pjmedia_vid_codec_mgr *mgr);
421
422
423
/**
424
 * Get the default codec manager instance.
425
 *
426
 * @return          The default codec manager instance or NULL if none.
427
 */
428
PJ_DECL(pjmedia_vid_codec_mgr*) pjmedia_vid_codec_mgr_instance(void);
429
430
431
/**
432
 * Set the default codec manager instance.
433
 *
434
 * @param mgr       The codec manager instance.
435
 */
436
PJ_DECL(void) pjmedia_vid_codec_mgr_set_instance(pjmedia_vid_codec_mgr* mgr);
437
438
439
/** 
440
 * Register codec factory to codec manager. This will also register
441
 * all supported codecs in the factory to the codec manager.
442
 *
443
 * @param mgr       The codec manager instance. If NULL, the default codec
444
 *                  manager instance will be used.
445
 * @param factory   The codec factory to be registered.
446
 *
447
 * @return          PJ_SUCCESS on success.
448
 */
449
PJ_DECL(pj_status_t) 
450
pjmedia_vid_codec_mgr_register_factory( pjmedia_vid_codec_mgr *mgr,
451
                                        pjmedia_vid_codec_factory *factory);
452
453
/**
454
 * Unregister codec factory from the codec manager. This will also
455
 * remove all the codecs registered by the codec factory from the
456
 * codec manager's list of supported codecs.
457
 *
458
 * @param mgr       The codec manager instance. If NULL, the default codec
459
 *                  manager instance will be used.
460
 * @param factory   The codec factory to be unregistered.
461
 *
462
 * @return          PJ_SUCCESS on success.
463
 */
464
PJ_DECL(pj_status_t) 
465
pjmedia_vid_codec_mgr_unregister_factory( pjmedia_vid_codec_mgr *mgr, 
466
                                          pjmedia_vid_codec_factory *factory);
467
468
/**
469
 * Enumerate all supported codecs that have been registered to the
470
 * codec manager by codec factories.
471
 *
472
 * @param mgr       The codec manager instance. If NULL, the default codec
473
 *                  manager instance will be used.
474
 * @param count     On input, specifies the number of elements in
475
 *                  the array. On output, the value will be set to
476
 *                  the number of elements that have been initialized
477
 *                  by this function.
478
 * @param info      The codec info array, which contents will be 
479
 *                  initialized upon return.
480
 * @param prio      Optional pointer to receive array of codec priorities.
481
 *
482
 * @return          PJ_SUCCESS on success.
483
 */
484
PJ_DECL(pj_status_t)
485
pjmedia_vid_codec_mgr_enum_codecs(pjmedia_vid_codec_mgr *mgr,
486
                                  unsigned *count,
487
                                  pjmedia_vid_codec_info info[],
488
                                  unsigned *prio);
489
490
491
/**
492
 * Get codec info for the specified payload type. The payload type must be
493
 * static or locally defined in #pjmedia_video_pt.
494
 *
495
 * @param mgr       The codec manager instance. If NULL, the default codec
496
 *                  manager instance will be used.
497
 * @param pt        The payload type/number.
498
 * @param info      Pointer to receive codec info.
499
 *
500
 * @return          PJ_SUCCESS on success.
501
 */
502
PJ_DECL(pj_status_t) 
503
pjmedia_vid_codec_mgr_get_codec_info( pjmedia_vid_codec_mgr *mgr,
504
                                      unsigned pt,
505
                                      const pjmedia_vid_codec_info **info);
506
507
508
/**
509
 * Get codec info for the specified format ID.
510
 *
511
 * @param mgr       The codec manager instance. If NULL, the default codec
512
 *                  manager instance will be used.
513
 * @param fmt_id    Format ID. See #pjmedia_format_id
514
 * @param info      Pointer to receive codec info.
515
 *
516
 * @return          PJ_SUCCESS on success.
517
 */
518
PJ_DECL(pj_status_t) 
519
pjmedia_vid_codec_mgr_get_codec_info2(pjmedia_vid_codec_mgr *mgr,
520
                                      pjmedia_format_id fmt_id,
521
                                      const pjmedia_vid_codec_info **info);
522
523
524
/**
525
 * Convert codec info struct into a unique codec identifier.
526
 * A codec identifier looks something like "H263/34", where "H263" is the
527
 * codec name and "34" is the (default) payload type.
528
 *
529
 * @param info      The codec info
530
 * @param id        Buffer to put the codec info string.
531
 * @param max_len   The length of the buffer.
532
 *
533
 * @return          The null terminated codec info string, or NULL if
534
 *                  the buffer is not long enough.
535
 */
536
PJ_DECL(char*) pjmedia_vid_codec_info_to_id(const pjmedia_vid_codec_info *info,
537
                                            char *id, unsigned max_len );
538
539
540
/**
541
 * Find codecs by the unique codec identifier. This function will find
542
 * all codecs that match the codec identifier prefix. For example, if
543
 * "H26" is specified, then it will find "H263", "H264", and so on,
544
 * up to the maximum count specified in the argument.
545
 *
546
 * @param mgr       The codec manager instance. If NULL, the default codec
547
 *                  manager instance will be used.
548
 * @param codec_id  The full codec ID or codec ID prefix. If an empty
549
 *                  string is given, it will match all codecs.
550
 * @param count     Maximum number of codecs to find. On return, it
551
 *                  contains the actual number of codecs found.
552
 * @param p_info    Array of pointer to codec info to be filled. This
553
 *                  argument may be NULL, which in this case, only
554
 *                  codec count will be returned.
555
 * @param prio      Optional array of codec priorities.
556
 *
557
 * @return          PJ_SUCCESS if at least one codec info is found.
558
 */
559
PJ_DECL(pj_status_t) 
560
pjmedia_vid_codec_mgr_find_codecs_by_id(pjmedia_vid_codec_mgr *mgr,
561
                                        const pj_str_t *codec_id,
562
                                        unsigned *count,
563
                                        const pjmedia_vid_codec_info *p_info[],
564
                                        unsigned prio[]);
565
566
567
/**
568
 * Set codec priority. The codec priority determines the order of
569
 * the codec in the SDP created by the endpoint. If more than one codecs
570
 * are found with the same codec_id prefix, then the function sets the
571
 * priorities of all those codecs.
572
 *
573
 * @param mgr       The codec manager instance. If NULL, the default codec
574
 *                  manager instance will be used.
575
 * @param codec_id  The full codec ID or codec ID prefix. If an empty
576
 *                  string is given, it will match all codecs.
577
 * @param prio      Priority to be set. The priority can have any value
578
 *                  between 1 to 255. When the priority is set to zero,
579
 *                  the codec will be disabled.
580
 *
581
 * @return          PJ_SUCCESS if at least one codec info is found.
582
 */
583
PJ_DECL(pj_status_t)
584
pjmedia_vid_codec_mgr_set_codec_priority(pjmedia_vid_codec_mgr *mgr, 
585
                                         const pj_str_t *codec_id,
586
                                         pj_uint8_t prio);
587
588
589
/**
590
 * Get default codec param for the specified codec info.
591
 *
592
 * @param mgr       The codec manager instance. If NULL, the default codec
593
 *                  manager instance will be used.
594
 * @param info      The codec info, which default parameter's is being
595
 *                  queried.
596
 * @param param     On return, will be filled with the default codec
597
 *                  parameter.
598
 *
599
 * @return          PJ_SUCCESS on success.
600
 */
601
PJ_DECL(pj_status_t) 
602
pjmedia_vid_codec_mgr_get_default_param(pjmedia_vid_codec_mgr *mgr,
603
                                        const pjmedia_vid_codec_info *info,
604
                                        pjmedia_vid_codec_param *param);
605
606
607
/**
608
 * Set default codec param for the specified codec info.
609
 *
610
 * @param mgr       The codec manager instance. If NULL, the default codec
611
 *                  manager instance will be used.
612
 * @param info      The codec info, which default parameter's is being
613
 *                  updated.
614
 * @param param     The new default codec parameter. Note that encoding video
615
 *                  codec resolution must be even numbers. Set to NULL to
616
 *                  reset codec parameter to library default settings.
617
 *
618
 * @return          PJ_SUCCESS on success, or the appropriate error code.
619
 */
620
PJ_DECL(pj_status_t) 
621
pjmedia_vid_codec_mgr_set_default_param(pjmedia_vid_codec_mgr *mgr,
622
                                        const pjmedia_vid_codec_info *info,
623
                                        const pjmedia_vid_codec_param *param);
624
625
626
/**
627
 * Request the codec manager to allocate one instance of codec with the
628
 * specified codec info. The codec will enumerate all codec factories
629
 * until it finds factory that is able to create the specified codec.
630
 *
631
 * @param mgr       The codec manager instance. If NULL, the default codec
632
 *                  manager instance will be used.
633
 * @param info      The information about the codec to be created.
634
 * @param p_codec   Pointer to receive the codec instance.
635
 *
636
 * @return          PJ_SUCCESS on success.
637
 */
638
PJ_DECL(pj_status_t) 
639
pjmedia_vid_codec_mgr_alloc_codec( pjmedia_vid_codec_mgr *mgr, 
640
                                   const pjmedia_vid_codec_info *info,
641
                                   pjmedia_vid_codec **p_codec);
642
643
/**
644
 * Deallocate the specified codec instance. The codec manager will return
645
 * the instance of the codec back to its factory.
646
 *
647
 * @param mgr       The codec manager instance. If NULL, the default codec
648
 *                  manager instance will be used.
649
 * @param codec     The codec instance.
650
 *
651
 * @return          PJ_SUCESS on success.
652
 */
653
PJ_DECL(pj_status_t) pjmedia_vid_codec_mgr_dealloc_codec(
654
                                                pjmedia_vid_codec_mgr *mgr, 
655
                                                pjmedia_vid_codec *codec);
656
657
658
659
/** 
660
 * Initialize codec using the specified attribute.
661
 *
662
 * @param codec     The codec instance.
663
 * @param pool      Pool to use when the codec needs to allocate
664
 *                  some memory.
665
 *
666
 * @return          PJ_SUCCESS on success.
667
 */
668
PJ_INLINE(pj_status_t) pjmedia_vid_codec_init( pjmedia_vid_codec *codec, 
669
                                               pj_pool_t *pool )
670
0
{
671
0
    return (*codec->op->init)(codec, pool);
672
0
}
Unexecuted instantiation: rtcp_fb.c:pjmedia_vid_codec_init
Unexecuted instantiation: vid_codec.c:pjmedia_vid_codec_init
Unexecuted instantiation: endpoint.c:pjmedia_vid_codec_init
673
674
675
/** 
676
 * Open the codec and initialize with the specified parameter.
677
 * Upon successful initialization, the codec may modify the parameter
678
 * and fills in the unspecified values (such as size or frame rate of
679
 * the encoder format, as it may need to be negotiated with remote
680
 * preferences via SDP fmtp).
681
 *
682
 * @param codec     The codec instance.
683
 * @param param     Codec initialization parameter. Note that encoding video
684
 *                  codec resolution must be even numbers.
685
 *
686
 * @return          PJ_SUCCESS on success, or the appropriate error code.
687
 */
688
PJ_INLINE(pj_status_t) pjmedia_vid_codec_open(pjmedia_vid_codec *codec,
689
                                              pjmedia_vid_codec_param *param)
690
0
{
691
0
    if (param && ((param->enc_fmt.det.vid.size.w % 2 == 1) ||
692
0
        (param->enc_fmt.det.vid.size.h % 2 == 1)))
693
0
    {
694
0
        return PJ_EINVAL;
695
0
    }
696
0
697
0
    return (*codec->op->open)(codec, param);
698
0
}
Unexecuted instantiation: rtcp_fb.c:pjmedia_vid_codec_open
Unexecuted instantiation: vid_codec.c:pjmedia_vid_codec_open
Unexecuted instantiation: endpoint.c:pjmedia_vid_codec_open
699
700
701
/** 
702
 * Close and shutdown codec, releasing all resources allocated by
703
 * this codec, if any.
704
 *
705
 * @param codec     The codec instance.
706
 *
707
 * @return          PJ_SUCCESS on success.
708
 */
709
PJ_INLINE(pj_status_t) pjmedia_vid_codec_close( pjmedia_vid_codec *codec )
710
0
{
711
0
    return (*codec->op->close)(codec);
712
0
}
Unexecuted instantiation: rtcp_fb.c:pjmedia_vid_codec_close
Unexecuted instantiation: vid_codec.c:pjmedia_vid_codec_close
Unexecuted instantiation: endpoint.c:pjmedia_vid_codec_close
713
714
715
/** 
716
 * Modify the codec parameter after the codec is opened.
717
 * Note that not all codec backends support modifying parameters during
718
 * runtime and only certain parameters can be changed.
719
 *
720
 * Currently, only Video Toolbox and OpenH264 backends support runtime
721
 * adjustment of encoding bitrate (avg_bps and max_bps).
722
 *
723
 * @param codec         The codec instance.
724
 * @param param         The new codec parameter.
725
 *
726
 * @return              PJ_SUCCESS on success, or the appropriate error code.
727
 */
728
PJ_INLINE(pj_status_t)
729
pjmedia_vid_codec_modify(pjmedia_vid_codec *codec,
730
                         const pjmedia_vid_codec_param *param)
731
0
{
732
0
    if (param && ((param->enc_fmt.det.vid.size.w % 2 == 1) ||
733
0
        (param->enc_fmt.det.vid.size.h % 2 == 1)))
734
0
    {
735
0
        return PJ_EINVAL;
736
0
    }
737
0
738
0
    return (*codec->op->modify)(codec, param);
739
0
}
Unexecuted instantiation: rtcp_fb.c:pjmedia_vid_codec_modify
Unexecuted instantiation: vid_codec.c:pjmedia_vid_codec_modify
Unexecuted instantiation: endpoint.c:pjmedia_vid_codec_modify
740
741
742
/** 
743
 * Get the codec parameter after the codec is opened. 
744
 *
745
 * @param codec The codec instance.
746
 * @param param The codec parameter.
747
 *
748
 * @return              PJ_SUCCESS on success.
749
 */
750
PJ_INLINE(pj_status_t)
751
pjmedia_vid_codec_get_param(pjmedia_vid_codec *codec,
752
                            pjmedia_vid_codec_param *param)
753
0
{
754
0
    return (*codec->op->get_param)(codec, param);
755
0
}
Unexecuted instantiation: rtcp_fb.c:pjmedia_vid_codec_get_param
Unexecuted instantiation: vid_codec.c:pjmedia_vid_codec_get_param
Unexecuted instantiation: endpoint.c:pjmedia_vid_codec_get_param
756
757
/** 
758
 * Encode the specified input frame. The input MUST contain only one picture
759
 * with the appropriate format as specified when opening the codec. Depending
760
 * on the packing or packetization set in the \a packing param, the process
761
 * may produce multiple encoded packets or payloads to represent the picture.
762
 * This is true for example for PJMEDIA_VID_PACKING_PACKETS packing. In this
763
 * case, the \a has_more field will be set to PJ_TRUE, and application should
764
 * call pjmedia_vid_codec_encode_more() to get the remaining results from the
765
 * codec.
766
 *
767
 * @param codec         The codec instance.
768
 * @param opt           Optional encoding options.
769
 * @param input         The input frame.
770
 * @param out_size      The length of buffer in the output frame. This
771
 *                      should be at least the same as the configured
772
 *                      encoding MTU of the codec.
773
 * @param output        The output frame.
774
 * @param has_more      PJ_TRUE if more payloads are available; application
775
 *                      should then call pjmedia_vid_codec_encode_more()
776
 *                      to retrieve the remaining results.
777
 *
778
 * @return              PJ_SUCCESS on success;
779
 */
780
PJ_INLINE(pj_status_t)
781
pjmedia_vid_codec_encode_begin( pjmedia_vid_codec *codec,
782
                                const pjmedia_vid_encode_opt *opt,
783
                                const pjmedia_frame *input,
784
                                unsigned out_size,
785
                                pjmedia_frame *output,
786
                                pj_bool_t *has_more)
787
0
{
788
0
    return (*codec->op->encode_begin)(codec, opt, input, out_size, output,
789
0
                                      has_more);
790
0
}
Unexecuted instantiation: rtcp_fb.c:pjmedia_vid_codec_encode_begin
Unexecuted instantiation: vid_codec.c:pjmedia_vid_codec_encode_begin
Unexecuted instantiation: endpoint.c:pjmedia_vid_codec_encode_begin
791
792
/**
793
 * Retrieve more encoded packets/payloads from the codec. Application
794
 * should call this function repeatedly until \a has_more flag is set
795
 * to PJ_FALSE.
796
 *
797
 * @param codec         The codec instance.
798
 * @param out_size      The length of buffer in the output frame. This
799
 *                      should be at least the same as as the configured
800
 *                      encoding MTU of the codec.
801
 * @param output        The output frame.
802
 * @param has_more      PJ_TRUE if more payloads are available, which in
803
 *                      this case application should call \a encode_more()
804
 *                      to retrieve them.
805
 *
806
 * @return              PJ_SUCCESS on success;
807
 */
808
PJ_INLINE(pj_status_t)
809
pjmedia_vid_codec_encode_more( pjmedia_vid_codec *codec,
810
                               unsigned out_size,
811
                               pjmedia_frame *output,
812
                               pj_bool_t *has_more)
813
0
{
814
0
    return (*codec->op->encode_more)(codec, out_size, output, has_more);
815
0
}
Unexecuted instantiation: rtcp_fb.c:pjmedia_vid_codec_encode_more
Unexecuted instantiation: vid_codec.c:pjmedia_vid_codec_encode_more
Unexecuted instantiation: endpoint.c:pjmedia_vid_codec_encode_more
816
817
/** 
818
 * Decode the input packets into one picture. If the packing is set to
819
 * PJMEDIA_VID_PACKING_PACKETS when opening the codec, the codec is set
820
 * to decode multiple encoded packets into one picture. These encoded
821
 * packets are typically retrieved from the jitter buffer. If the packing
822
 * is set to PJMEDIA_VID_PACKING_WHOLE, then this decode function can only
823
 * accept one frame as the input.
824
 *
825
 * Note that the decoded picture format may different to the configured
826
 * setting (i.e. the format specified in the #pjmedia_vid_codec_param when
827
 * opening the codec), in this case the PJMEDIA_EVENT_FMT_CHANGED event will
828
 * be emitted by the codec to notify the event. The codec parameter will
829
 * also be updated, and application can query the format by using
830
 * pjmedia_vid_codec_get_param().
831
 *
832
 * @param codec         The codec instance.
833
 * @param pkt_count     Number of packets in the input.
834
 * @param packets       Array of input packets, each containing an encoded
835
 *                      frame.
836
 * @param out_size      The length of buffer in the output frame.
837
 * @param output        The output frame.
838
 *
839
 * @return              PJ_SUCCESS on success;
840
 */
841
PJ_INLINE(pj_status_t) pjmedia_vid_codec_decode(pjmedia_vid_codec *codec,
842
                                                pj_size_t pkt_count,
843
                                                pjmedia_frame packets[],
844
                                                unsigned out_size,
845
                                                pjmedia_frame *output)
846
0
{
847
0
    return (*codec->op->decode)(codec, pkt_count, packets, out_size, output);
848
0
}
Unexecuted instantiation: rtcp_fb.c:pjmedia_vid_codec_decode
Unexecuted instantiation: vid_codec.c:pjmedia_vid_codec_decode
Unexecuted instantiation: endpoint.c:pjmedia_vid_codec_decode
849
850
/**
851
 * Recover a missing frame.
852
 *
853
 * @param codec         The codec instance.
854
 * @param out_size      The length of buffer in the output frame.
855
 * @param output        The output frame where generated signal
856
 *                      will be placed.
857
 *
858
 * @return              PJ_SUCCESS on success;
859
 */
860
PJ_INLINE(pj_status_t) pjmedia_vid_codec_recover(pjmedia_vid_codec *codec,
861
                                                 unsigned out_size,
862
                                                 pjmedia_frame *output)
863
0
{
864
0
    if (codec->op && codec->op->recover)
865
0
        return (*codec->op->recover)(codec, out_size, output);
866
0
    else
867
0
        return PJ_ENOTSUP;
868
0
}
Unexecuted instantiation: rtcp_fb.c:pjmedia_vid_codec_recover
Unexecuted instantiation: vid_codec.c:pjmedia_vid_codec_recover
Unexecuted instantiation: endpoint.c:pjmedia_vid_codec_recover
869
870
871
/**
872
 * @}
873
 */
874
875
/**
876
 * @defgroup PJMEDIA_CODEC_VID_CODECS Supported video codecs
877
 * @ingroup PJMEDIA_VID_CODEC
878
 */
879
880
881
/*
882
 * Internal functions.
883
 */
884
885
/**
886
 * Internal: Get the array of codec identifiers that have dynamic PT.
887
 */
888
pj_status_t pjmedia_vid_codec_mgr_get_dyn_codecs(pjmedia_vid_codec_mgr* mgr,
889
                                                 pj_int8_t *count,
890
                                                 pj_str_t dyn_codecs[]);
891
892
893
PJ_END_DECL
894
895
896
#endif  /* __PJMEDIA_VID_CODEC_H__ */