source: svn/newcon3bcm2_21bu/BSEAV/api/src/nexus/bsettop_transcode.c @ 22

Last change on this file since 22 was 22, checked in by phkim, 11 years ago
  1. phkim
  2. newcon3sk 를 kctv 로 브랜치 함
  • Property svn:executable set to *
File size: 16.6 KB
Line 
1/***************************************************************************
2 *     Copyright (c) 2003-2008, Broadcom Corporation
3 *     All Rights Reserved
4 *     Confidential Property of Broadcom Corporation
5 *
6 *  THIS SOFTWARE MAY ONLY BE USED SUBJECT TO AN EXECUTED SOFTWARE LICENSE
7 *  AGREEMENT  BETWEEN THE USER AND BROADCOM.  YOU HAVE NO RIGHT TO USE OR
8 *  EXPLOIT THIS MATERIAL EXCEPT SUBJECT TO THE TERMS OF SUCH AN AGREEMENT.
9 *
10 * $brcm_Workfile: bsettop_transcode.c $
11 * $brcm_Revision: 11 $
12 * $brcm_Date: 9/11/08 12:39p $
13 *
14 * Module Description:
15 *
16 * Revision History:
17 *
18 * $brcm_Log: /BSEAV/api/src/nexus/bsettop_transcode.c $
19 *
20 * 11   9/11/08 12:39p shyam
21 * PR46778 : Add audiooasthru support to brutus
22 *
23 * 10   9/10/08 6:53p shyam
24 * PR46778 : Port brutus to B0 firmwre rel 2.2
25 *
26 * 9   8/12/08 6:58p shyam
27 * PR43426 : Fix transcode disable mode
28 *
29 * 8   8/12/08 5:09p shyam
30 * PR43426 : Add support for I only and debug function
31 *
32 * 7   7/30/08 8:13p shyam
33 * PR43426 : Add programming of Qp
34 *
35 * 6   7/28/08 5:25p shyam
36 * PR 45076 : Add transcode support for streams originating on a playback
37 * channel
38 *
39 * 5   7/8/08 4:20p shyam
40 * PR 42338 : Add audio support
41 * PR 42636 : Add support for diferernt PCR and Video Pids
42 *
43 * 4   7/2/08 1:41p shyam
44 * PR 42338 : Add audio support
45 *
46 * 3   6/26/08 2:40p shyam
47 * PR43426 : fix stubs to enable regular builds
48 *
49 * 2   6/25/08 12:54p shyam
50 * PR43426 : Add stubs to enable regualr builds
51 *
52 * 1   6/24/08 6:23p shyam
53 * PR43426 : Add 7043 Transcode support
54 *
55 ***************************************************************************/
56#include "bsettop_impl.h"
57
58BDBG_MODULE(transcode);
59
60
61#ifdef B_HAS_TRANSCODE
62
63#define B_HAS_TRANSCODE_AUDIO 1
64
65struct btranscode g_transcode[B_MAX_TRANSCODES] ;
66
67/**
68Summary:
69        Initialize encoder settings for a particular quality level.
70**/
71void btranscode_settings_init(
72    btranscode_settings *settings, /* [out] settings to be initialized */
73    bencode_quality quality, /* quality level to use when chosing initial settings */
74    bencode_vpp_mode vpp_mode       /* vpp settings to set to*/
75    )
76{
77        BSTD_UNUSED(quality) ;
78        BSTD_UNUSED(vpp_mode) ;
79        BKNI_Memset( settings, 0, sizeof( *settings) ) ;
80        settings->realtime = true;
81        settings->program.video[0].format = bvideo_codec_h264 ;
82        settings->program.video[0].width = 720 ;
83        settings->program.video[0].height= 480 ;
84        settings->program.video[0].bitrate = 25000000 ;
85        settings->program.video[0].pid = 0x21 ;
86        settings->program.video[0].progressive = true ;
87       
88        settings->program.audio[0].format = baudio_format_ac3;
89        settings->program.audio[0].passthrough = true ;
90        settings->program.audio[0].samplerate = 44100;
91        settings->program.audio[0].bitrate = 100000 ; 
92        settings->program.audio[0].pid = 0x24;
93
94        settings->program.pcr_pid = 0x21 ;
95       
96        settings->stream_type = bstream_mpeg_type_ts ;
97        settings->transport_bitrate = 30000000 ; 
98}
99
100/*
101Summary:
102    Open a transcode engine
103Description:
104*/
105btranscode_t btranscode_open(
106    bobject_t transcode_id   /* transcode object id */
107   )
108{
109    btranscode_t transcode;
110        NEXUS_RemuxSettings remuxSettings ;
111        NEXUS_RemuxHandle rmx;
112
113    unsigned index = B_ID_GET_INDEX(transcode_id);
114    if (index >= B_MAX_TRANSCODES)
115    {
116        BSETTOP_ERROR(berr_not_available);
117        return NULL;
118    }
119        transcode = &g_transcode[index];
120
121        NEXUS_Remux_GetDefaultSettings(&remuxSettings) ;
122        transcode->rmx[0] = rmx = NEXUS_Remux_Open(0, &remuxSettings);
123        if(NULL == rmx)
124        {
125                goto error ;
126        }
127
128        /* End of open */
129    return transcode;
130error:
131    btranscode_close(transcode);
132    return NULL;
133}
134
135/*
136Summary:
137    Close a transcode
138*/
139void btranscode_close(
140    btranscode_t transcode /* handle returned by btranscode_open */
141    )
142{
143        if(transcode->rmx[0])
144                NEXUS_Remux_Close(transcode->rmx[0]) ;
145}
146
147bresult btranscode_p_start_video_transcode(
148    btranscode_t transcode, /* handle returned by btranscode_open */
149    bstream_t source   /* source for the decode, either analog or digital */
150    )
151{
152        NEXUS_Transcoder_OutputConfiguration portConfig ;
153        NEXUS_Transcoder_OutputPortHandle hPortHandle;
154        NEXUS_Transcoder_OutputChannel outputPort ;
155        NEXUS_Transcoder_OpenVideoTranscodeSettings openSettings ;
156        NEXUS_VideoCodec outputVideoCodec ;
157
158        /* Transcoder stuff */
159        BKNI_Memset( &portConfig, 0 , sizeof(portConfig) );
160        portConfig.transportBitrate = transcode->settings.transport_bitrate ;
161        outputPort.outputChNum = 0;
162        outputPort.outputType = 
163                NEXUS_Transcoder_OutputChannelType_eTxSerialOut ;
164        hPortHandle = NEXUS_Transcoder_OpenOutputPort(outputPort, &portConfig);
165        BDBG_ERR(("Port handle = %p", hPortHandle));
166        if(NULL==hPortHandle)
167        {
168                return BSETTOP_ERROR(berr_invalid_state) ;
169        }
170        transcode->hPortHandle = hPortHandle ;
171
172        BKNI_Memset( &openSettings, 0 , sizeof(openSettings) );
173        openSettings.bRealTime = transcode->settings.realtime ;
174        openSettings.inputType = NEXUS_Transcoder_VideoInputChannelType_eTxSerialIn ;
175        openSettings.inputChNum = 1 ;
176        openSettings.inputStreamType = NEXUS_TransportType_eTs ;
177        BDBG_ERR(("source Stream pid = %08x", source->mpeg.video[0].pid));
178        BDBG_ERR(("source Stream pid = %08x", source->mpeg.pcr_pid));
179        BDBG_ERR(("source format = %08x", source->mpeg.video[0].format));
180        openSettings.inputStreamId = source->mpeg.video[0].pid ;
181        openSettings.inputPcrPid =  source->mpeg.pcr_pid ;
182        openSettings.inputVideoCodec = 
183                b_videocodec2nexus(source->mpeg.video[0].format) ;
184
185        /* Video Encode/Output Settings */
186        openSettings.outputVideoCodec = outputVideoCodec = 
187                b_videocodec2nexus(transcode->settings.program.video[0].format) ;
188        openSettings.outputStreamType = NEXUS_TransportType_eTs ;
189        openSettings.outputPort = hPortHandle ;
190        if( NEXUS_VideoCodec_eH264 == outputVideoCodec )
191        {
192                openSettings.codingSettings.avcCoding.h264Level = NEXUS_Transcoder_H264Level_eL4 ;
193                openSettings.codingSettings.avcCoding.h264Profile = NEXUS_Transcoder_H264Profile_eMain ;
194        }
195        else if( NEXUS_VideoCodec_eMpeg2 == outputVideoCodec )
196        {
197                openSettings.codingSettings.mpegCoding.mpegLevel = NEXUS_Transcoder_MPEGLevel_eMain ;
198                openSettings.codingSettings.mpegCoding.mpegProfile = NEXUS_Transcoder_MPEGProfile_eMain ;
199        }
200        else if( NEXUS_VideoCodec_eMpeg4Part2 == outputVideoCodec )
201        {
202                openSettings.codingSettings.mpeg4Coding.mpeg4Level = NEXUS_Transcoder_MPEG4Level_e1;
203                openSettings.codingSettings.mpeg4Coding.mpeg4Profile = NEXUS_Transcoder_MPEG4Profile_eSimple;
204        }
205       
206        /** Transport Settings */
207        openSettings.outputStreamId = transcode->settings.program.video[0].pid ;
208        openSettings.transportBitrate = transcode->settings.transport_bitrate; /* Bits per Second */
209
210        openSettings.outWidth = transcode->settings.program.video[0].width ;
211        openSettings.outHeight = transcode->settings.program.video[0].height ;
212
213        openSettings.bProgressive = transcode->settings.program.video[0].progressive;
214
215        openSettings.esPeakRateControl = NEXUS_Transcoder_PeakRateControl_eConstantQp;
216        openSettings.esPeakBitrate = 14 ;
217
218        if (bsettop_get_config("qpvalue")) {
219                openSettings.esPeakBitrate = atoi(bsettop_get_config("qpvalue"));
220                BDBG_WRN(("setting Qp Value %d", openSettings.esPeakBitrate));
221        }
222        /** VBI Settings */
223        openSettings.enableVbi = false ;
224
225        transcode->nexus_transcoder = NEXUS_Transcoder_OpenVideoTranscode(&openSettings) ;
226        BDBG_ERR(("Open transcoder handle = %p", transcode->nexus_transcoder));
227        if(NULL == transcode->nexus_transcoder)
228        {
229                return BSETTOP_ERROR(berr_invalid_state) ;
230        }
231
232        if(bsettop_get_config("ionly"))
233        {
234                NEXUS_Transcoder_VideoEncodeSettings vidEncSettings ;
235                BDBG_ERR(("\n********** Enable I Only *************\n"));
236                NEXUS_Transcoder_GetVideoEncodeSettings(transcode->nexus_transcoder, &vidEncSettings );
237                vidEncSettings.gopStructure = NEXUS_Transcoder_GOPStructure_eI_Picture ;
238                NEXUS_Transcoder_SetVideoEncodeSettings(transcode->nexus_transcoder, &vidEncSettings );
239        }
240
241
242        NEXUS_Transcoder_Start(transcode->nexus_transcoder) ;
243
244        return b_ok ;
245}
246
247
248bresult btranscode_p_start_audio_transcode(
249    btranscode_t transcode, /* handle returned by btranscode_open */
250    bstream_t source   /* source for the decode, either analog or digital */
251    )
252{
253        NEXUS_TranscoderHandle audTranscoder ;
254        NEXUS_Transcoder_OpenAudioTranscodeSettings openAudSettings ;
255
256        BKNI_Memset( &openAudSettings, 0, sizeof(openAudSettings) ); 
257        openAudSettings.inputChNum = 1 ;
258        openAudSettings.inputType = NEXUS_Transcoder_AudioInputChannelType_eTxSerialIn ;
259        openAudSettings.inputAudioStreamId = source->mpeg.audio[0].pid ;
260        openAudSettings.inputPcrPid = source->mpeg.pcr_pid ;
261        openAudSettings.outputPort = transcode->hPortHandle ;
262        audTranscoder = NEXUS_Transcoder_OpenAudioTranscode(&openAudSettings) ;
263        NEXUS_Transcoder_Start(audTranscoder) ;
264
265        return b_ok ;
266}
267
268bresult btranscode_p_enable_remux(
269    btranscode_t transcode, /* handle returned by btranscode_open */
270    bstream_t source   /* source for the decode, either analog or digital */
271    )
272{
273        NEXUS_Error nrc ;
274        NEXUS_PidChannelHandle vidPidChannel, audPidChannel, pcrPidChannel ;
275
276        BDBG_MSG(("%s, Video Pid = %x",
277                (NULL != source->producer.band) ? "Parser Band" : "Playback Band",
278                source->mpeg.video[0].pid));
279        BDBG_ERR(("Audio Pid = %x", source->mpeg.audio[0].pid));
280        /* Open Video Pid channel : Since we are getting a bstream_t object
281          It means the pid channel already exists so we will get an existing handle
282          no need to worry about settings for this Pidchannel Open call */
283        vidPidChannel = bstream_p_open_pid(
284                                        source,
285                                        source->mpeg.video[0].pid, 
286                                        bstream_pid_type_video) ;
287        nrc = NEXUS_Remux_AddPidChannel(transcode->rmx[0], vidPidChannel) ;
288        if(nrc != NEXUS_SUCCESS)
289                return BSETTOP_ERROR(nrc) ;
290
291#if B_HAS_TRANSCODE_AUDIO
292        audPidChannel = bstream_p_open_pid(
293                                        source,
294                                        source->mpeg.audio[0].pid, 
295                                        bstream_pid_type_audio) ;
296        nrc = NEXUS_Remux_AddPidChannel(transcode->rmx[0], audPidChannel) ;
297        if(nrc != NEXUS_SUCCESS)
298                return BSETTOP_ERROR(nrc) ;
299#endif
300
301        if( source->mpeg.pcr_pid != source->mpeg.video[0].pid &&
302                source->mpeg.pcr_pid != source->mpeg.audio[0].pid )
303        {
304                pcrPidChannel = bstream_p_open_pid(
305                                                source,
306                                                source->mpeg.pcr_pid, 
307                                                bstream_pid_type_pcr) ;
308                nrc = NEXUS_Remux_AddPidChannel(transcode->rmx[0], pcrPidChannel) ;
309                if(nrc != NEXUS_SUCCESS)
310                        return BSETTOP_ERROR(nrc) ;
311        }
312
313        NEXUS_Remux_Start(transcode->rmx[0]) ;
314       
315        return b_ok ;
316}
317
318/*
319Summary:
320    Start transcoding a stream.
321*/
322bstream_t btranscode_start(
323    btranscode_t transcode, /* handle returned by btranscode_open */
324    bstream_t source,   /* source for the transcode, either analog or digital */
325    const btranscode_settings *settings /* [out] settings to be initialized */
326    )
327{
328        bresult brc ;
329        bband_t band;
330        bstream_t dest ;
331        bstream_mpeg mpeg;
332
333        BDBG_OBJECT_ASSERT(source, bstream);
334        BDBG_ASSERT(settings);
335
336        /* Remux stuff */
337        brc = btranscode_p_enable_remux(transcode, source) ;
338        if(brc != b_ok)
339                return NULL ;
340
341        transcode->settings = *settings ;
342
343        /* Transcoder Stuff */
344        brc = btranscode_p_start_video_transcode(transcode, source) ;
345        if(brc != b_ok)
346                return NULL ;
347
348#if B_HAS_TRANSCODE_AUDIO
349        brc = btranscode_p_start_audio_transcode(transcode, source) ;
350        if(brc != b_ok)
351                return NULL ;
352#endif
353
354        /* Assume Transcoder is connected to IB2 for now */
355        band = bstreamer_attach( B_ID(102), bstream_mpeg_type_ts);
356        if (!band) goto error;
357
358        bstream_mpeg_init(&mpeg);
359        mpeg.video[0].pid = transcode->settings.program.video[0].pid;
360        mpeg.video[0].format = transcode->settings.program.video[0].format;
361#if B_HAS_TRANSCODE_AUDIO
362        mpeg.audio[0].pid = transcode->settings.program.audio[0].pid;
363        mpeg.audio[0].format = transcode->settings.program.audio[0].format;
364#else
365        mpeg.audio[0].pid = 0 ;
366        mpeg.audio[0].format = baudio_format_unknown ;
367#endif
368        mpeg.pcr_pid = transcode->settings.program.pcr_pid;
369
370        dest = bstream_open(band, &mpeg);
371        if (!dest) goto error;
372
373        return dest ;
374error :
375        return NULL ;
376}
377
378/*
379Summary:
380    Stop transcoding a stream.
381Description:
382    The stream remains valid after transcode is stopped.
383*/
384void btranscode_stop(
385    btranscode_t transcode /* handle returned by btranscode_open */
386    )
387{
388    BSTD_UNUSED(transcode);
389    BSETTOP_ERROR(berr_not_supported);
390}
391
392
393/*
394Summary:
395    Pause a stream transcode.
396*/
397bresult btranscode_pause(
398    btranscode_t transcode /* handle returned by btranscode_open */
399    )
400{
401    BSTD_UNUSED(transcode);
402    return BSETTOP_ERROR(berr_not_supported);
403}
404
405
406/*
407Summary:
408    Resume a stream transcode.
409*/
410bresult btranscode_resume(
411    btranscode_t transcode /* handle returned by btranscode_open */
412    )
413{
414    BSTD_UNUSED(transcode);
415    return BSETTOP_ERROR(berr_not_supported);
416}
417
418/*
419Summary:
420    Get Settings for a stream transcode
421Description:
422    Get aand Set settings will take care of dyanmic parameter changes
423*/
424void btranscode_get(
425    btranscode_t transcode, /* handle returned by btranscode_open */
426    btranscode_settings *settings
427    )
428{
429        BDBG_ASSERT(transcode);
430        *settings = transcode->settings ;
431}
432
433
434/*
435Summary:
436    Get Settings for a stream transcode
437Description:
438    Get aand Set settings will take care of dyanmic parameter changes
439*/
440bresult btranscode_set(
441    btranscode_t transcode, /* handle returned by btranscode_open */
442    const btranscode_settings *settings
443    )
444{
445    BSTD_UNUSED(transcode);
446    BSTD_UNUSED(settings);
447    return BSETTOP_ERROR(berr_not_supported);
448}
449
450
451/*
452Summary:
453    Get Settings for a stream transcode
454Description:
455    Get aand Set settings will take care of dyanmic parameter changes
456*/
457bresult btranscode_get_status(
458    btranscode_t transcode, /* handle returned by btranscode_open */
459    btranscode_status *status
460    ) 
461{
462    BSTD_UNUSED(transcode);
463    BSTD_UNUSED(status);
464    return BSETTOP_ERROR(berr_not_supported);
465}
466
467/*
468Summary:
469    For debugging the transcoder
470*/
471void btranscode_debug(int loops)
472{
473        NEXUS_Transcoder_Debug(loops) ;
474}
475
476#else
477
478btranscode_t btranscode_open(
479    bobject_t transcode_id   /* transcode object id */
480   )
481{
482    BSTD_UNUSED(transcode_id);
483    BSETTOP_ERROR(berr_not_supported);
484    return NULL ;
485}
486
487/**
488Summary:
489        Initialize transcoder settings for a particular quality level.
490**/
491void btranscode_settings_init(
492    btranscode_settings *settings, /* [out] settings to be initialized */
493    bencode_quality quality, /* quality level to use when chosing initial settings */
494    bencode_vpp_mode vpp_mode       /* vpp settings to set to*/
495    )
496{
497    BSTD_UNUSED(settings);
498    BSTD_UNUSED(quality);
499    BSTD_UNUSED(vpp_mode);
500    BSETTOP_ERROR(berr_not_supported);
501}
502
503/*
504Summary:
505    Close a transcode
506*/
507void btranscode_close(
508    btranscode_t transcode /* handle returned by btranscode_open */
509    )
510{
511    BSTD_UNUSED(transcode);
512    BSETTOP_ERROR(berr_not_supported);
513}
514
515/*
516Summary:
517    Start transcoding a stream.
518*/
519bstream_t btranscode_start(
520    btranscode_t transcode, /* handle returned by btranscode_open */
521    bstream_t source,   /* source for the transcode, either analog or digital */
522    const btranscode_settings *settings /* [out] settings to be initialized */
523    )
524{
525    BSTD_UNUSED(transcode);
526    BSTD_UNUSED(source);
527    BSTD_UNUSED(settings);
528    BSETTOP_ERROR(berr_not_supported);
529    return NULL ;
530}
531
532/*
533Summary:
534    Stop transcoding a stream.
535Description:
536    The stream remains valid after transcode is stopped.
537*/
538void btranscode_stop(
539    btranscode_t transcode /* handle returned by btranscode_open */
540    )
541{
542    BSTD_UNUSED(transcode);
543    BSETTOP_ERROR(berr_not_supported);
544}
545
546
547/*
548Summary:
549    Pause a stream transcode.
550*/
551bresult btranscode_pause(
552    btranscode_t transcode /* handle returned by btranscode_open */
553    )
554{
555    BSTD_UNUSED(transcode);
556    return BSETTOP_ERROR(berr_not_supported);
557}
558
559
560/*
561Summary:
562    Resume a stream transcode.
563*/
564bresult btranscode_resume(
565    btranscode_t transcode /* handle returned by btranscode_open */
566    )
567{
568    BSTD_UNUSED(transcode);
569    return BSETTOP_ERROR(berr_not_supported);
570}
571
572
573/*
574Summary:
575    Get Settings for a stream transcode
576Description:
577    Get aand Set settings will take care of dyanmic parameter changes
578*/
579void btranscode_get(
580    btranscode_t transcode, /* handle returned by btranscode_open */
581    btranscode_settings *settings
582    ) 
583{
584    BSTD_UNUSED(transcode);
585    BSTD_UNUSED(settings);
586    BSETTOP_ERROR(berr_not_supported);
587}
588
589
590/*
591Summary:
592    Set Settings for a stream transcode
593Description:
594    Sets the transcoder settings
595*/
596bresult btranscode_set(
597    btranscode_t transcode, /* handle returned by btranscode_open */
598    const btranscode_settings *settings
599    ) 
600{
601    BSTD_UNUSED(transcode);
602    BSTD_UNUSED(settings);
603    return BSETTOP_ERROR(berr_not_supported);
604}
605
606
607/*
608Summary:
609    Get Settings for a stream transcode
610Description:
611    Get aand Set settings will take care of dyanmic parameter changes
612*/
613bresult btranscode_get_status(
614    btranscode_t transcode, /* handle returned by btranscode_open */
615    btranscode_status *status
616    ) 
617{
618    BSTD_UNUSED(transcode);
619    BSTD_UNUSED(status);
620    return BSETTOP_ERROR(berr_not_supported);
621}
622
623#endif
624
625
Note: See TracBrowser for help on using the repository browser.