summaryrefslogtreecommitdiffstats
path: root/bindings/_common/ProxyProducer.cxx
blob: 087a2d27015c3aaa6c5c788dd1883707aab2dcfe (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
/*
* Copyright (C) 2010-2011 Mamadou Diop.
*
* Contact: Mamadou Diop <diopmamadou(at)doubango.org>
*
* This file is part of Open Source Doubango Framework.
*
* DOUBANGO 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 3 of the License, or
* (at your option) any later version.
*
* DOUBANGO 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 DOUBANGO.
*
*/

/**@file ProxyProducer.c
 * @brief Audio/Video proxy producers.
 *
 * @author Mamadou Diop <diopmamadou(at)doubango.org>
 *

 */
#include "ProxyProducer.h"

#include "tsk_timer.h"
#include "tsk_memory.h"
#include "tsk_debug.h"

#include "tinydav/audio/tdav_producer_audio.h"


/* ============ Audio Media Producer Interface ================= */
typedef struct twrap_producer_proxy_audio_s {
    TDAV_DECLARE_PRODUCER_AUDIO;

    uint64_t id;
    tsk_bool_t started;
}
twrap_producer_proxy_audio_t;
#define TWRAP_PRODUCER_PROXY_AUDIO(self) ((twrap_producer_proxy_audio_t*)(self))

static int twrap_producer_proxy_audio_set(tmedia_producer_t* _self, const tmedia_param_t* param)
{
    twrap_producer_proxy_audio_t* self = (twrap_producer_proxy_audio_t*)_self;
    if(param->plugin_type == tmedia_ppt_producer) {
        // specific proxy producer
    }
    return tdav_producer_audio_set(TDAV_PRODUCER_AUDIO(self), param);
}

static int twrap_producer_proxy_audio_prepare(tmedia_producer_t* self, const tmedia_codec_t* codec)
{
    ProxyPluginMgr* manager;
    int ret = -1;
    if(codec && (manager = ProxyPluginMgr::getInstance())) {
        const ProxyAudioProducer* audioProducer;
        if((audioProducer = manager->findAudioProducer(TWRAP_PRODUCER_PROXY_AUDIO(self)->id)) && audioProducer->getCallback()) {
            self->audio.channels = TMEDIA_CODEC_CHANNELS_AUDIO_ENCODING(codec);
            self->audio.rate = TMEDIA_CODEC_RATE_ENCODING(codec);
            self->audio.ptime = TMEDIA_CODEC_PTIME_AUDIO_ENCODING(codec);
            ret = audioProducer->getCallback()->prepare((int)self->audio.ptime, self->audio.rate, self->audio.channels);
        }
    }
    return ret;
}

static int twrap_producer_proxy_audio_start(tmedia_producer_t* self)
{
    ProxyPluginMgr* manager;
    int ret = -1;
    if((manager = ProxyPluginMgr::getInstance())) {
        const ProxyAudioProducer* audioProducer;
        if((audioProducer = manager->findAudioProducer(TWRAP_PRODUCER_PROXY_AUDIO(self)->id)) && audioProducer->getCallback()) {
            const_cast<ProxyAudioProducer*>(audioProducer)->startPushCallback();
            ret = audioProducer->getCallback()->start();
        }
    }

    TWRAP_PRODUCER_PROXY_AUDIO(self)->started = (ret == 0);
    return ret;
}

static int twrap_producer_proxy_audio_pause(tmedia_producer_t* self)
{
    ProxyPluginMgr* manager;
    int ret = -1;
    if((manager = ProxyPluginMgr::getInstance())) {
        const ProxyAudioProducer* audioProducer;
        if((audioProducer = manager->findAudioProducer(TWRAP_PRODUCER_PROXY_AUDIO(self)->id)) && audioProducer->getCallback()) {
            ret = audioProducer->getCallback()->pause();
        }
    }
    return ret;
}

static int twrap_producer_proxy_audio_stop(tmedia_producer_t* self)
{
    ProxyPluginMgr* manager;
    int ret = -1;
    if((manager = ProxyPluginMgr::getInstance())) {
        const ProxyAudioProducer* audioProducer;
        if((audioProducer = manager->findAudioProducer(TWRAP_PRODUCER_PROXY_AUDIO(self)->id)) && audioProducer->getCallback()) {
            const_cast<ProxyAudioProducer*>(audioProducer)->stopPushCallback();
            ret = audioProducer->getCallback()->stop();
        }
    }
    TWRAP_PRODUCER_PROXY_AUDIO(self)->started = (ret == 0) ? tsk_false : tsk_true;
    return ret;
}


//
//	Audio producer object definition
//
/* constructor */
static tsk_object_t* twrap_producer_proxy_audio_ctor(tsk_object_t * self, va_list * app)
{
    twrap_producer_proxy_audio_t *producer = (twrap_producer_proxy_audio_t *)self;
    if(producer) {
        /* init base */
        tdav_producer_audio_init(TDAV_PRODUCER_AUDIO(producer));
        /* init self */

        /* Add the plugin to the manager */
        ProxyPluginMgr* manager = ProxyPluginMgr::getInstance();
        if(manager) {
            ProxyPlugin* proxyProducer = new ProxyAudioProducer(producer);
            uint64_t id = proxyProducer->getId();
            manager->addPlugin(&proxyProducer);
            manager->getCallback()->OnPluginCreated(id, twrap_proxy_plugin_audio_producer);
        }
    }
    return self;
}
/* destructor */
static tsk_object_t* twrap_producer_proxy_audio_dtor(tsk_object_t * self)
{
    twrap_producer_proxy_audio_t *producer = (twrap_producer_proxy_audio_t *)self;
    if(producer) {

        /* stop */
        if(producer->started) {
            twrap_producer_proxy_audio_stop(TMEDIA_PRODUCER(producer));
        }

        /* deinit base */
        tdav_producer_audio_deinit(TDAV_PRODUCER_AUDIO(producer));
        /* deinit self */

        /* Remove plugin from the manager */
        ProxyPluginMgr* manager = ProxyPluginMgr::getInstance();
        if(manager) {
            manager->getCallback()->OnPluginDestroyed(producer->id, twrap_proxy_plugin_audio_producer);
            manager->removePlugin(producer->id);
        }
    }

    return self;
}
/* object definition */
static const tsk_object_def_t twrap_producer_proxy_audio_def_s = {
    sizeof(twrap_producer_proxy_audio_t),
    twrap_producer_proxy_audio_ctor,
    twrap_producer_proxy_audio_dtor,
    tdav_producer_audio_cmp,
};
/* plugin definition*/
static const tmedia_producer_plugin_def_t twrap_producer_proxy_audio_plugin_def_s = {
    &twrap_producer_proxy_audio_def_s,

    tmedia_audio,
    "Audio Proxy Producer",

    twrap_producer_proxy_audio_set,
    twrap_producer_proxy_audio_prepare,
    twrap_producer_proxy_audio_start,
    twrap_producer_proxy_audio_pause,
    twrap_producer_proxy_audio_stop
};

/*TINYWRAP_GEXTERN*/ const tmedia_producer_plugin_def_t *twrap_producer_proxy_audio_plugin_def_t = &twrap_producer_proxy_audio_plugin_def_s;



/* ============ ProxyAudioProducer Class ================= */
ProxyAudioProducer::ProxyAudioProducer(twrap_producer_proxy_audio_t* pProducer)
    :m_pCallback(tsk_null), m_pWrappedPlugin(pProducer), m_bUsePushCallback(false), m_hPushTimerMgr(tsk_null), ProxyPlugin(twrap_proxy_plugin_audio_producer)
{
    m_pWrappedPlugin->id = this->getId();
    m_PushBuffer.pPushBufferPtr = tsk_null;
    m_PushBuffer.nPushBufferSize = 0;
}

ProxyAudioProducer::~ProxyAudioProducer()
{
    stopPushCallback();
}

// Use this function to request resampling when your sound card can't honor negotaited record parameters
bool ProxyAudioProducer::setActualSndCardRecordParams(int nPtime, int nRate, int nChannels)
{
    if(m_pWrappedPlugin) {
        TSK_DEBUG_INFO("setActualSndCardRecordParams(ptime=%d, rate=%d, channels=%d)", nPtime, nRate, nChannels);
        TMEDIA_PRODUCER(m_pWrappedPlugin)->audio.ptime = nPtime;
        TMEDIA_PRODUCER(m_pWrappedPlugin)->audio.rate = nRate;
        TMEDIA_PRODUCER(m_pWrappedPlugin)->audio.channels = nChannels;
        return true;
    }
    else {
        TSK_DEBUG_ERROR("Invalid state");
        return false;
    }
}

bool ProxyAudioProducer::setPushBuffer(const void* pPushBufferPtr, unsigned nPushBufferSize, bool bUsePushCallback/*=false*/)
{
    m_PushBuffer.pPushBufferPtr = pPushBufferPtr;
    m_PushBuffer.nPushBufferSize = nPushBufferSize;
    m_bUsePushCallback = bUsePushCallback;

    if(!pPushBufferPtr || !nPushBufferSize || !bUsePushCallback) {
        return stopPushCallback();
    }
    else if(m_bUsePushCallback && m_pWrappedPlugin && m_pWrappedPlugin->started) {
        return startPushCallback();
    }
    return true;
}

int ProxyAudioProducer::push(const void* _pBuffer/*=tsk_null*/, unsigned _nSize/*=0*/)
{
    if(m_pWrappedPlugin && TMEDIA_PRODUCER(m_pWrappedPlugin)->enc_cb.callback) {
        const void* pBuffer;
        unsigned nSize;
        if(_pBuffer && _nSize) {
            pBuffer = _pBuffer, nSize = _nSize;
        }
        else {
            pBuffer = m_PushBuffer.pPushBufferPtr, nSize = m_PushBuffer.nPushBufferSize;
        }
        return TMEDIA_PRODUCER(m_pWrappedPlugin)->enc_cb.callback(TMEDIA_PRODUCER(m_pWrappedPlugin)->enc_cb.callback_data, pBuffer, nSize);
    }
    return 0;
}

bool ProxyAudioProducer::setGain(unsigned nGain)
{
    if(m_pWrappedPlugin) {
        // see also: MediaSessionMgr.producerSetInt32(org.doubango.tinyWRAP.twrap_media_type_t.twrap_media_audio, "gain", nGain);
        TMEDIA_PRODUCER(m_pWrappedPlugin)->audio.gain = TSK_MIN(nGain,14);
        return true;
    }
    return false;
}

unsigned ProxyAudioProducer::getGain()
{
    if(m_pWrappedPlugin) {
        return TMEDIA_PRODUCER(m_pWrappedPlugin)->audio.gain;
    }
    return 0;
}

bool ProxyAudioProducer::startPushCallback()
{
    if(!m_bUsePushCallback) {
        return true;
    }

    if(!m_pWrappedPlugin) {
        TSK_DEBUG_ERROR("Not wrapping plugin");
        return false;
    }

    if(!m_hPushTimerMgr) {
        if(!(m_hPushTimerMgr = tsk_timer_manager_create())) {
            TSK_DEBUG_ERROR("Failed to create timer manager");
            return false;
        }
    }

    if(!TSK_RUNNABLE(m_hPushTimerMgr)->started) {
        if((tsk_timer_manager_start(m_hPushTimerMgr)) == 0) {
            m_uPushTimer = tsk_timer_manager_schedule(m_hPushTimerMgr, TMEDIA_PRODUCER(m_pWrappedPlugin)->audio.ptime, &ProxyAudioProducer::pushTimerCallback, this);
        }
        else {
            TSK_DEBUG_ERROR("Failed to start timer");
            return false;
        }
    }
    return true;
}

bool ProxyAudioProducer::stopPushCallback()
{
    if(m_hPushTimerMgr) {
        tsk_timer_manager_destroy(&m_hPushTimerMgr);
    }
    return true;
}

int ProxyAudioProducer::pushTimerCallback(const void* arg, tsk_timer_id_t timer_id)
{
    ProxyAudioProducer* This = (ProxyAudioProducer*)arg;

    This->m_uPushTimer = tsk_timer_manager_schedule(This->m_hPushTimerMgr, TMEDIA_PRODUCER(This->m_pWrappedPlugin)->audio.ptime, &ProxyAudioProducer::pushTimerCallback, This);

    if(This->m_pCallback) {
        if(This->m_pCallback->fillPushBuffer() == 0) {
            return This->push();
        }
    }
    return 0;
}

bool ProxyAudioProducer::registerPlugin()
{
    /* HACK: Unregister all other audio plugins */
    tmedia_producer_plugin_unregister_by_type(tmedia_audio);
    /* Register our proxy plugin */
    return (tmedia_producer_plugin_register(twrap_producer_proxy_audio_plugin_def_t) == 0);
}























/* ============ Video Media Producer Interface ================= */
typedef struct twrap_producer_proxy_video_s {
    TMEDIA_DECLARE_PRODUCER;

    int rotation;
    uint64_t id;
    tsk_bool_t started;
#if 0
    // https://code.google.com/p/doubango/issues/detail?id=416
    // The lock on the producer is useless because all tinyDAV proxied functions (push(), stop(), prepare()...) are already thread safe.
    // Locking the push method while tinDAV locks the stop() function produce a deadlock on Android devices with slow video producer implementations (e.g. Hovis Box v1)
    TSK_DECLARE_SAFEOBJ;
#endif
}
twrap_producer_proxy_video_t;
#define TWRAP_PRODUCER_PROXY_VIDEO(self) ((twrap_producer_proxy_video_t*)(self))

int twrap_producer_proxy_video_set(tmedia_producer_t* self, const tmedia_param_t* params)
{
    return 0;
}

int twrap_producer_proxy_video_prepare(tmedia_producer_t* self, const tmedia_codec_t* codec)
{
    ProxyPluginMgr* manager;
    int ret = -1;
    if(codec && (manager = ProxyPluginMgr::getInstance())) {
        const ProxyVideoProducer* videoProducer;
        if((videoProducer = manager->findVideoProducer(TWRAP_PRODUCER_PROXY_VIDEO(self)->id)) && videoProducer->getCallback()) {
            self->video.chroma = videoProducer->getChroma();
            self->video.rotation = videoProducer->getRotation();
            ret = videoProducer->getCallback()->prepare(TMEDIA_CODEC_VIDEO(codec)->out.width, TMEDIA_CODEC_VIDEO(codec)->out.height, TMEDIA_CODEC_VIDEO(codec)->out.fps);
        }
    }

    return ret;
}

int twrap_producer_proxy_video_start(tmedia_producer_t* self)
{
    ProxyPluginMgr* manager;
    int ret = -1;
    if((manager = ProxyPluginMgr::getInstance())) {
        const ProxyVideoProducer* videoProducer;
        if((videoProducer = manager->findVideoProducer(TWRAP_PRODUCER_PROXY_VIDEO(self)->id)) && videoProducer->getCallback()) {
            ret = videoProducer->getCallback()->start();
            TWRAP_PRODUCER_PROXY_VIDEO(self)->started = (ret == 0);
        }
    }

    return ret;
}

int twrap_producer_proxy_video_pause(tmedia_producer_t* self)
{
    ProxyPluginMgr* manager;
    int ret = -1;
    if((manager = ProxyPluginMgr::getInstance())) {
        const ProxyVideoProducer* videoProducer;
        if((videoProducer = manager->findVideoProducer(TWRAP_PRODUCER_PROXY_VIDEO(self)->id)) && videoProducer->getCallback()) {
            ret = videoProducer->getCallback()->pause();
        }
    }

    return ret;
}

int twrap_producer_proxy_video_stop(tmedia_producer_t* self)
{
    ProxyPluginMgr* manager;
    int ret = -1;
    if((manager = ProxyPluginMgr::getInstance())) {
        const ProxyVideoProducer* videoProducer;
        if((videoProducer = manager->findVideoProducer(TWRAP_PRODUCER_PROXY_VIDEO(self)->id)) && videoProducer->getCallback()) {
            ret = videoProducer->getCallback()->stop();
            TWRAP_PRODUCER_PROXY_VIDEO(self)->started = ((ret == 0) ? tsk_false : tsk_true);
        }
    }

    return ret;
}


//
//	Video producer object definition
//
/* constructor */
static tsk_object_t* twrap_producer_proxy_video_ctor(tsk_object_t * self, va_list * app)
{
    twrap_producer_proxy_video_t *producer = (twrap_producer_proxy_video_t *)self;
    if(producer) {
        /* init base */
        tmedia_producer_init(TMEDIA_PRODUCER(producer));
        /* init self */

        /* Add the plugin to the manager */
        ProxyPluginMgr* manager = ProxyPluginMgr::getInstance();
        if(manager) {
            ProxyPlugin* proxyProducer = new ProxyVideoProducer(ProxyVideoProducer::getDefaultChroma(), producer);
            uint64_t id = proxyProducer->getId();
            manager->addPlugin(&proxyProducer);
            manager->getCallback()->OnPluginCreated(id, twrap_proxy_plugin_video_producer);
        }
    }
    return self;
}
/* destructor */
static tsk_object_t* twrap_producer_proxy_video_dtor(tsk_object_t * self)
{
    twrap_producer_proxy_video_t *producer = (twrap_producer_proxy_video_t *)self;
    if(producer) {
        TSK_DEBUG_INFO("twrap_producer_proxy_video_dtor()");
        /* stop */
        if(producer->started) {
            twrap_producer_proxy_video_stop(TMEDIA_PRODUCER(producer));
        }

        /* deinit base */
        tmedia_producer_deinit(TMEDIA_PRODUCER(producer));
        /* deinit self */

        /* Remove plugin from the manager */
        ProxyPluginMgr* manager = ProxyPluginMgr::getInstance();
        if(manager) {
            manager->getCallback()->OnPluginDestroyed(producer->id, twrap_proxy_plugin_video_producer);
            manager->removePlugin(producer->id);
        }
    }

    return self;
}
/* object definition */
static const tsk_object_def_t twrap_producer_proxy_video_def_s = {
    sizeof(twrap_producer_proxy_video_t),
    twrap_producer_proxy_video_ctor,
    twrap_producer_proxy_video_dtor,
    tsk_null,
};
/* plugin definition*/
static const tmedia_producer_plugin_def_t twrap_producer_proxy_video_plugin_def_s = {
    &twrap_producer_proxy_video_def_s,

    tmedia_video,
    "Video Proxy Producer",

    twrap_producer_proxy_video_set,
    twrap_producer_proxy_video_prepare,
    twrap_producer_proxy_video_start,
    twrap_producer_proxy_video_pause,
    twrap_producer_proxy_video_stop
};

/*TINYWRAP_GEXTERN*/ const tmedia_producer_plugin_def_t *twrap_producer_proxy_video_plugin_def_t = &twrap_producer_proxy_video_plugin_def_s;



/* ============ ProxyVideoProducer Class ================= */
tmedia_chroma_t ProxyVideoProducer::s_eDefaultChroma = tmedia_chroma_nv21;

ProxyVideoProducer::ProxyVideoProducer(tmedia_chroma_t eChroma, struct twrap_producer_proxy_video_s* pProducer)
    :m_pCallback(tsk_null), m_eChroma(eChroma), m_nRotation(0), m_bMirror(false), m_pWrappedPlugin(pProducer), ProxyPlugin(twrap_proxy_plugin_video_producer)
{
    if(m_pWrappedPlugin) {
        m_pWrappedPlugin->id = this->getId();
    }
}

ProxyVideoProducer::~ProxyVideoProducer()
{
    TSK_DEBUG_INFO("~ProxyVideoProducer");
}

int ProxyVideoProducer::getRotation()const
{
    return m_nRotation;
}

bool ProxyVideoProducer::setRotation(int nRot)
{
    m_nRotation = nRot;
    if (m_pWrappedPlugin) {
        TMEDIA_PRODUCER(m_pWrappedPlugin)->video.rotation = m_nRotation;
        return true;
    }
    return false;
}

bool ProxyVideoProducer::getMirror()const
{
    return m_bMirror;
}

bool ProxyVideoProducer::setMirror(bool bMirror)
{
    m_bMirror = bMirror;
    if (m_pWrappedPlugin) {
        TMEDIA_PRODUCER(m_pWrappedPlugin)->video.mirror = m_bMirror ? tsk_true : tsk_false;
        return true;
    }
    return false;
}

// alert the encoder which size your camera is using because it's very hard to retrieve it from send(buffer, size) function
// this function is only needed if the actual size (output from your camera) is different than the negociated one
bool ProxyVideoProducer::setActualCameraOutputSize(unsigned nWidth, unsigned nHeight)
{
    if(m_pWrappedPlugin) {
        TMEDIA_PRODUCER(m_pWrappedPlugin)->video.width = nWidth;
        TMEDIA_PRODUCER(m_pWrappedPlugin)->video.height = nHeight;
        return true;
    }
    return false;
}

// encode() then send()
int ProxyVideoProducer::push(const void* pBuffer, unsigned nSize)
{
    if (m_pWrappedPlugin && TMEDIA_PRODUCER(m_pWrappedPlugin)->enc_cb.callback) {
        int ret = -1;
        if (m_pWrappedPlugin->started) {
            ret = TMEDIA_PRODUCER(m_pWrappedPlugin)->enc_cb.callback(TMEDIA_PRODUCER(m_pWrappedPlugin)->enc_cb.callback_data, pBuffer, nSize);
        }
        return ret;
    }
    return 0;
}

// send() "as is"
// only used by telepresence system with a H.264 SVC hardaware encoder
int ProxyVideoProducer::sendRaw(const void* pBuffer, unsigned nSize, unsigned nDuration, bool bMarker)
{
    if(m_pWrappedPlugin && TMEDIA_PRODUCER(m_pWrappedPlugin)->raw_cb.callback) {
        //tmedia_video_encode_result_reset(&TMEDIA_PRODUCER(m_pWrappedPlugin)->raw_cb.chunck_curr);

        TMEDIA_PRODUCER(m_pWrappedPlugin)->raw_cb.chunck_curr.buffer.ptr = pBuffer;
        TMEDIA_PRODUCER(m_pWrappedPlugin)->raw_cb.chunck_curr.buffer.size = nSize;
        TMEDIA_PRODUCER(m_pWrappedPlugin)->raw_cb.chunck_curr.duration = nDuration;
        TMEDIA_PRODUCER(m_pWrappedPlugin)->raw_cb.chunck_curr.last_chunck = (bMarker == true);
        return TMEDIA_PRODUCER(m_pWrappedPlugin)->raw_cb.callback(&TMEDIA_PRODUCER(m_pWrappedPlugin)->raw_cb.chunck_curr);
    }
    return 0;
}

int ProxyVideoProducer::sendRaw(const void* pBuffer, unsigned nSize, const void* proto_hdr)
{
    if(m_pWrappedPlugin && TMEDIA_PRODUCER(m_pWrappedPlugin)->raw_cb.callback) {
        //tmedia_video_encode_result_reset(&TMEDIA_PRODUCER(m_pWrappedPlugin)->raw_cb.chunck_curr);

        TMEDIA_PRODUCER(m_pWrappedPlugin)->raw_cb.chunck_curr.buffer.ptr = pBuffer;
        TMEDIA_PRODUCER(m_pWrappedPlugin)->raw_cb.chunck_curr.buffer.size = nSize;
        TMEDIA_PRODUCER(m_pWrappedPlugin)->raw_cb.chunck_curr.proto_hdr = proto_hdr;
        return TMEDIA_PRODUCER(m_pWrappedPlugin)->raw_cb.callback(&TMEDIA_PRODUCER(m_pWrappedPlugin)->raw_cb.chunck_curr);
    }
    return 0;
}

tmedia_chroma_t ProxyVideoProducer::getChroma()const
{
    return m_eChroma;
}

bool ProxyVideoProducer::registerPlugin()
{
    /* HACK: Unregister all other video plugins */
    tmedia_producer_plugin_unregister_by_type(tmedia_video);
    /* Register our proxy plugin */
    return (tmedia_producer_plugin_register(twrap_producer_proxy_video_plugin_def_t) == 0);
}
OpenPOWER on IntegriCloud