| 1 | /****************************************************************************** |
|---|
| 2 | * (c)2008-2012 Broadcom Corporation |
|---|
| 3 | * |
|---|
| 4 | * This program is the proprietary software of Broadcom Corporation and/or its licensors, |
|---|
| 5 | * and may only be used, duplicated, modified or distributed pursuant to the terms and |
|---|
| 6 | * conditions of a separate, written license agreement executed between you and Broadcom |
|---|
| 7 | * (an "Authorized License"). Except as set forth in an Authorized License, Broadcom grants |
|---|
| 8 | * no license (express or implied), right to use, or waiver of any kind with respect to the |
|---|
| 9 | * Software, and Broadcom expressly reserves all rights in and to the Software and all |
|---|
| 10 | * intellectual property rights therein. IF YOU HAVE NO AUTHORIZED LICENSE, THEN YOU |
|---|
| 11 | * HAVE NO RIGHT TO USE THIS SOFTWARE IN ANY WAY, AND SHOULD IMMEDIATELY |
|---|
| 12 | * NOTIFY BROADCOM AND DISCONTINUE ALL USE OF THE SOFTWARE. |
|---|
| 13 | * |
|---|
| 14 | * Except as expressly set forth in the Authorized License, |
|---|
| 15 | * |
|---|
| 16 | * 1. This program, including its structure, sequence and organization, constitutes the valuable trade |
|---|
| 17 | * secrets of Broadcom, and you shall use all reasonable efforts to protect the confidentiality thereof, |
|---|
| 18 | * and to use this information only in connection with your use of Broadcom integrated circuit products. |
|---|
| 19 | * |
|---|
| 20 | * 2. TO THE MAXIMUM EXTENT PERMITTED BY LAW, THE SOFTWARE IS PROVIDED "AS IS" |
|---|
| 21 | * AND WITH ALL FAULTS AND BROADCOM MAKES NO PROMISES, REPRESENTATIONS OR |
|---|
| 22 | * WARRANTIES, EITHER EXPRESS, IMPLIED, STATUTORY, OR OTHERWISE, WITH RESPECT TO |
|---|
| 23 | * THE SOFTWARE. BROADCOM SPECIFICALLY DISCLAIMS ANY AND ALL IMPLIED WARRANTIES |
|---|
| 24 | * OF TITLE, MERCHANTABILITY, NONINFRINGEMENT, FITNESS FOR A PARTICULAR PURPOSE, |
|---|
| 25 | * LACK OF VIRUSES, ACCURACY OR COMPLETENESS, QUIET ENJOYMENT, QUIET POSSESSION |
|---|
| 26 | * OR CORRESPONDENCE TO DESCRIPTION. YOU ASSUME THE ENTIRE RISK ARISING OUT OF |
|---|
| 27 | * USE OR PERFORMANCE OF THE SOFTWARE. |
|---|
| 28 | * |
|---|
| 29 | * 3. TO THE MAXIMUM EXTENT PERMITTED BY LAW, IN NO EVENT SHALL BROADCOM OR ITS |
|---|
| 30 | * LICENSORS BE LIABLE FOR (i) CONSEQUENTIAL, INCIDENTAL, SPECIAL, INDIRECT, OR |
|---|
| 31 | * EXEMPLARY DAMAGES WHATSOEVER ARISING OUT OF OR IN ANY WAY RELATING TO YOUR |
|---|
| 32 | * USE OF OR INABILITY TO USE THE SOFTWARE EVEN IF BROADCOM HAS BEEN ADVISED OF |
|---|
| 33 | * THE POSSIBILITY OF SUCH DAMAGES; OR (ii) ANY AMOUNT IN EXCESS OF THE AMOUNT |
|---|
| 34 | * ACTUALLY PAID FOR THE SOFTWARE ITSELF OR U.S. $1, WHICHEVER IS GREATER. THESE |
|---|
| 35 | * LIMITATIONS SHALL APPLY NOTWITHSTANDING ANY FAILURE OF ESSENTIAL PURPOSE OF |
|---|
| 36 | * ANY LIMITED REMEDY. |
|---|
| 37 | * |
|---|
| 38 | * $brcm_Workfile: decode.c $ |
|---|
| 39 | * $brcm_Revision: 16 $ |
|---|
| 40 | * $brcm_Date: 1/31/12 5:07p $ |
|---|
| 41 | * |
|---|
| 42 | * Module Description: |
|---|
| 43 | * |
|---|
| 44 | * Revision History: |
|---|
| 45 | * |
|---|
| 46 | * $brcm_Log: /nexus/utils/decode.c $ |
|---|
| 47 | * |
|---|
| 48 | * 16 1/31/12 5:07p rjlewis |
|---|
| 49 | * SW7425-1136: Added HDMI support (and some cleanup). |
|---|
| 50 | * |
|---|
| 51 | * 15 3/23/11 5:41p vsilyaev |
|---|
| 52 | * SW7422-406: Unified parsing of command line parameters |
|---|
| 53 | * |
|---|
| 54 | * 14 1/7/11 3:30p jtna |
|---|
| 55 | * SW7422-165: use NEXUS_VideoDecoderStatus.ptsStcDifference to calculate |
|---|
| 56 | * PTS - STC difference |
|---|
| 57 | * |
|---|
| 58 | * 13 12/13/10 4:07p erickson |
|---|
| 59 | * SW35230-179: add video bitrate using |
|---|
| 60 | * NEXUS_VideoDecoderStatus.numBytesDecoded |
|---|
| 61 | * |
|---|
| 62 | * 12 9/8/10 12:05p vsilyaev |
|---|
| 63 | * SW7468-129: Added video decoder on ZSP |
|---|
| 64 | * |
|---|
| 65 | * SW7468-129/1 3/5/10 7:31p vsilyaev |
|---|
| 66 | * SW7468-129: Added hooks for soft video decoder |
|---|
| 67 | * |
|---|
| 68 | * 11 12/30/09 2:23p erickson |
|---|
| 69 | * SW7550-128: add closed caption feature (-cc on) |
|---|
| 70 | * |
|---|
| 71 | * 10 8/18/09 4:36p vsilyaev |
|---|
| 72 | * PR 56809: Added option to control handling of video errors |
|---|
| 73 | * |
|---|
| 74 | * 9 6/8/09 7:06a erickson |
|---|
| 75 | * PR55617: add user-specific aspectRatio |
|---|
| 76 | * |
|---|
| 77 | * 8 3/18/09 10:26a erickson |
|---|
| 78 | * PR52350: add wxga/fha support with 50/60 hz option |
|---|
| 79 | * |
|---|
| 80 | * 7 3/6/09 9:33a erickson |
|---|
| 81 | * PR51743: added -ar and -graphics options, default DTV apps to panel |
|---|
| 82 | * output |
|---|
| 83 | * |
|---|
| 84 | * 6 2/5/09 2:08p erickson |
|---|
| 85 | * PR51151: update |
|---|
| 86 | * |
|---|
| 87 | * 5 1/23/09 5:12p erickson |
|---|
| 88 | * PR48944: update |
|---|
| 89 | * |
|---|
| 90 | * 4 1/22/09 7:48p vsilyaev |
|---|
| 91 | * PR 50848: Don't use globals for the command line options |
|---|
| 92 | * |
|---|
| 93 | * 3 11/20/08 12:50p erickson |
|---|
| 94 | * PR48944: update |
|---|
| 95 | * |
|---|
| 96 | * 2 11/17/08 2:19p erickson |
|---|
| 97 | * PR48944: update |
|---|
| 98 | * |
|---|
| 99 | ******************************************************************************/ |
|---|
| 100 | |
|---|
| 101 | #include "nexus_platform.h" |
|---|
| 102 | #include "nexus_pid_channel.h" |
|---|
| 103 | #include "nexus_parser_band.h" |
|---|
| 104 | #include "nexus_video_decoder.h" |
|---|
| 105 | #include "nexus_stc_channel.h" |
|---|
| 106 | #include "nexus_display.h" |
|---|
| 107 | #include "nexus_display_vbi.h" |
|---|
| 108 | #include "nexus_video_window.h" |
|---|
| 109 | #include "nexus_audio_dac.h" |
|---|
| 110 | #include "nexus_audio_decoder.h" |
|---|
| 111 | #include "nexus_audio_output.h" |
|---|
| 112 | #include "nexus_spdif_output.h" |
|---|
| 113 | #include "nexus_composite_output.h" |
|---|
| 114 | #include "nexus_component_output.h" |
|---|
| 115 | #if NEXUS_HAS_HDMI_OUTPUT |
|---|
| 116 | #include "nexus_hdmi_output.h" |
|---|
| 117 | #endif |
|---|
| 118 | #include "nexus_surface.h" |
|---|
| 119 | #include "nexus_core_utils.h" |
|---|
| 120 | |
|---|
| 121 | #include "bstd.h" |
|---|
| 122 | #include "bkni.h" |
|---|
| 123 | #include <stdio.h> |
|---|
| 124 | #include <stdlib.h> |
|---|
| 125 | #include <sys/time.h> |
|---|
| 126 | |
|---|
| 127 | #if NEXUS_HAS_ASTM |
|---|
| 128 | #include "nexus_astm.h" |
|---|
| 129 | #endif |
|---|
| 130 | #if NEXUS_HAS_SYNC_CHANNEL |
|---|
| 131 | #include "nexus_sync_channel.h" |
|---|
| 132 | #endif |
|---|
| 133 | |
|---|
| 134 | #include "cmdline_args.h" |
|---|
| 135 | |
|---|
| 136 | BDBG_MODULE(decode); |
|---|
| 137 | |
|---|
| 138 | static unsigned b_get_time(void) |
|---|
| 139 | { |
|---|
| 140 | struct timeval tv; |
|---|
| 141 | gettimeofday(&tv, NULL); |
|---|
| 142 | return tv.tv_sec*1000 + tv.tv_usec/1000; |
|---|
| 143 | } |
|---|
| 144 | |
|---|
| 145 | #if NEXUS_NUM_HDMI_OUTPUTS |
|---|
| 146 | /* registered HDMI hotplug handler -- changes the format (to monitor's default) if monitor doesn't support current format */ |
|---|
| 147 | static void hotplug_callback(void *pParam, int iParam) |
|---|
| 148 | { |
|---|
| 149 | NEXUS_HdmiOutputStatus hdmiStatus; |
|---|
| 150 | NEXUS_HdmiOutputHandle hdmi = pParam; |
|---|
| 151 | NEXUS_DisplayHandle display = (NEXUS_DisplayHandle)iParam; |
|---|
| 152 | NEXUS_AudioDecoderStartSettings audioProgram; |
|---|
| 153 | NEXUS_Error rc; |
|---|
| 154 | |
|---|
| 155 | rc = NEXUS_HdmiOutput_GetStatus(hdmi, &hdmiStatus); |
|---|
| 156 | /*fprintf(stderr, "HDMI event: %s\n", hdmiStatus.connected?"connected":"not connected");*/ |
|---|
| 157 | |
|---|
| 158 | /* the app can choose to switch to the preferred format, but it's not required. */ |
|---|
| 159 | if ( !rc && hdmiStatus.connected ) |
|---|
| 160 | { |
|---|
| 161 | NEXUS_DisplaySettings displaySettings; |
|---|
| 162 | NEXUS_Display_GetSettings(display, &displaySettings); |
|---|
| 163 | if ( !hdmiStatus.videoFormatSupported[displaySettings.format] ) |
|---|
| 164 | { |
|---|
| 165 | fprintf(stderr, "Current format not supported by attached monitor -- switching to preferred format (%d)\n", hdmiStatus.preferredVideoFormat); |
|---|
| 166 | if (hdmiStatus.preferredVideoFormat >= NEXUS_VideoFormat_e480p) |
|---|
| 167 | fprintf(stderr, "Warning: This format may disable composite output!\n"); |
|---|
| 168 | displaySettings.format = hdmiStatus.preferredVideoFormat; |
|---|
| 169 | NEXUS_Display_SetSettings(display, &displaySettings); |
|---|
| 170 | } |
|---|
| 171 | NEXUS_AudioDecoder_GetDefaultStartSettings(&audioProgram); |
|---|
| 172 | } |
|---|
| 173 | } |
|---|
| 174 | #endif |
|---|
| 175 | |
|---|
| 176 | int main(int argc, const char *argv[]) |
|---|
| 177 | { |
|---|
| 178 | NEXUS_PlatformSettings platformSettings; |
|---|
| 179 | NEXUS_PlatformConfiguration platformConfig; |
|---|
| 180 | NEXUS_InputBand inputBand; |
|---|
| 181 | NEXUS_ParserBand parserBand; |
|---|
| 182 | NEXUS_ParserBandSettings parserBandSettings; |
|---|
| 183 | NEXUS_StcChannelHandle stcChannel; |
|---|
| 184 | NEXUS_StcChannelSettings stcSettings; |
|---|
| 185 | NEXUS_PidChannelHandle pcrPidChannel, videoPidChannel, audioPidChannel; |
|---|
| 186 | NEXUS_DisplayHandle display; |
|---|
| 187 | NEXUS_DisplaySettings displaySettings; |
|---|
| 188 | NEXUS_DisplayVbiSettings displayVbiSettings; |
|---|
| 189 | NEXUS_VideoWindowHandle window; |
|---|
| 190 | NEXUS_VideoWindowSettings windowSettings; |
|---|
| 191 | NEXUS_VideoDecoderHandle videoDecoder; |
|---|
| 192 | NEXUS_VideoDecoderStartSettings videoProgram; |
|---|
| 193 | NEXUS_AudioDecoderHandle audioDecoder, audioPassthroughDecoder; |
|---|
| 194 | NEXUS_AudioDecoderStartSettings audioProgram; |
|---|
| 195 | #if NEXUS_HAS_ASTM |
|---|
| 196 | NEXUS_AstmSettings astmSettings; |
|---|
| 197 | NEXUS_AstmHandle astm; |
|---|
| 198 | #endif |
|---|
| 199 | #if NEXUS_HAS_SYNC_CHANNEL |
|---|
| 200 | NEXUS_SyncChannelSettings syncChannelSettings; |
|---|
| 201 | NEXUS_SyncChannelHandle syncChannel; |
|---|
| 202 | #endif |
|---|
| 203 | struct util_opts_t opts; |
|---|
| 204 | NEXUS_Error rc; |
|---|
| 205 | unsigned start; |
|---|
| 206 | |
|---|
| 207 | if (cmdline_parse(argc, argv, &opts)) { |
|---|
| 208 | return 0; |
|---|
| 209 | } |
|---|
| 210 | if (cmdline_probe(&opts.common, opts.filename, &opts.indexname)) { |
|---|
| 211 | return 1; |
|---|
| 212 | } |
|---|
| 213 | /* They MUST include a video and audio PID for the decode */ |
|---|
| 214 | if (!opts.common.videoPid && !opts.common.audioPid) { |
|---|
| 215 | BDBG_ERR(("Missing video or audio pid specification; See usage.")); |
|---|
| 216 | print_usage(argv[0]); |
|---|
| 217 | return 1; |
|---|
| 218 | } |
|---|
| 219 | |
|---|
| 220 | /* Bring up all modules for a platform in a default configuration for this platform */ |
|---|
| 221 | NEXUS_Platform_GetDefaultSettings(&platformSettings); |
|---|
| 222 | platformSettings.openFrontend = false; |
|---|
| 223 | rc = NEXUS_Platform_Init(&platformSettings); |
|---|
| 224 | BDBG_ASSERT(!rc); |
|---|
| 225 | NEXUS_Platform_GetConfiguration(&platformConfig); |
|---|
| 226 | |
|---|
| 227 | /* Get the streamer input band from Platform. Platform has already configured the FPGA with a default streamer routing */ |
|---|
| 228 | rc = NEXUS_Platform_GetStreamerInputBand(0, &inputBand); |
|---|
| 229 | BDBG_ASSERT(!rc); |
|---|
| 230 | |
|---|
| 231 | /* Map a parser band to the streamer input band. */ |
|---|
| 232 | parserBand = NEXUS_ParserBand_e0; |
|---|
| 233 | NEXUS_ParserBand_GetSettings(parserBand, &parserBandSettings); |
|---|
| 234 | parserBandSettings.sourceType = NEXUS_ParserBandSourceType_eInputBand; |
|---|
| 235 | parserBandSettings.sourceTypeSettings.inputBand = inputBand; |
|---|
| 236 | parserBandSettings.transportType = opts.common.transportType; |
|---|
| 237 | rc = NEXUS_ParserBand_SetSettings(parserBand, &parserBandSettings); |
|---|
| 238 | BDBG_ASSERT(!rc); |
|---|
| 239 | |
|---|
| 240 | /* Open the audio and video pid channels */ |
|---|
| 241 | pcrPidChannel = NEXUS_PidChannel_Open(parserBand, opts.common.pcrPid?opts.common.pcrPid:opts.common.videoPid, NULL); |
|---|
| 242 | videoPidChannel = NEXUS_PidChannel_Open(parserBand, opts.common.videoPid, NULL); |
|---|
| 243 | audioPidChannel = NEXUS_PidChannel_Open(parserBand, opts.common.audioPid, NULL); |
|---|
| 244 | |
|---|
| 245 | /* Open the StcChannel to do lipsync with the PCR */ |
|---|
| 246 | NEXUS_StcChannel_GetDefaultSettings(0, &stcSettings); |
|---|
| 247 | stcSettings.timebase = NEXUS_Timebase_e0; |
|---|
| 248 | stcSettings.mode = NEXUS_StcChannelMode_ePcr; /* live */ |
|---|
| 249 | stcSettings.modeSettings.pcr.pidChannel = pcrPidChannel; |
|---|
| 250 | stcChannel = NEXUS_StcChannel_Open(0, &stcSettings); |
|---|
| 251 | |
|---|
| 252 | #if NEXUS_HAS_SYNC_CHANNEL |
|---|
| 253 | if (opts.sync) { |
|---|
| 254 | NEXUS_SyncChannel_GetDefaultSettings(&syncChannelSettings); |
|---|
| 255 | syncChannel = NEXUS_SyncChannel_Create(&syncChannelSettings); |
|---|
| 256 | } |
|---|
| 257 | #endif |
|---|
| 258 | |
|---|
| 259 | /* Set up decoder Start structures now. We need to know the audio codec to properly set up the audio outputs. */ |
|---|
| 260 | NEXUS_VideoDecoder_GetDefaultStartSettings(&videoProgram); |
|---|
| 261 | videoProgram.codec = opts.common.videoCodec; |
|---|
| 262 | videoProgram.pidChannel = videoPidChannel; |
|---|
| 263 | videoProgram.stcChannel = stcChannel; |
|---|
| 264 | videoProgram.frameRate = opts.common.videoFrameRate; |
|---|
| 265 | videoProgram.aspectRatio = opts.common.aspectRatio; |
|---|
| 266 | videoProgram.sampleAspectRatio.x = opts.common.sampleAspectRatio.x; |
|---|
| 267 | videoProgram.sampleAspectRatio.y = opts.common.sampleAspectRatio.y; |
|---|
| 268 | videoProgram.errorHandling = opts.videoErrorHandling; |
|---|
| 269 | |
|---|
| 270 | NEXUS_AudioDecoder_GetDefaultStartSettings(&audioProgram); |
|---|
| 271 | audioProgram.codec = opts.common.audioCodec; |
|---|
| 272 | audioProgram.pidChannel = audioPidChannel; |
|---|
| 273 | audioProgram.stcChannel = stcChannel; |
|---|
| 274 | |
|---|
| 275 | /* Bring up audio decoders and outputs */ |
|---|
| 276 | audioDecoder = NEXUS_AudioDecoder_Open(0, NULL); |
|---|
| 277 | rc = NEXUS_AudioOutput_AddInput( |
|---|
| 278 | NEXUS_AudioDac_GetConnector(platformConfig.outputs.audioDacs[0]), |
|---|
| 279 | NEXUS_AudioDecoder_GetConnector(audioDecoder, NEXUS_AudioDecoderConnectorType_eStereo)); |
|---|
| 280 | BDBG_ASSERT(!rc); |
|---|
| 281 | |
|---|
| 282 | /* TODO: param for compressed passthrough of same or different pid */ |
|---|
| 283 | audioPassthroughDecoder = NEXUS_AudioDecoder_Open(1, NULL); |
|---|
| 284 | rc = NEXUS_AudioOutput_AddInput( |
|---|
| 285 | NEXUS_SpdifOutput_GetConnector(platformConfig.outputs.spdif[0]), |
|---|
| 286 | NEXUS_AudioDecoder_GetConnector(audioPassthroughDecoder, NEXUS_AudioDecoderConnectorType_eCompressed)); |
|---|
| 287 | BDBG_ASSERT(!rc); |
|---|
| 288 | |
|---|
| 289 | #if NEXUS_NUM_HDMI_OUTPUTS |
|---|
| 290 | if (opts.common.useHdmiOutput ) { |
|---|
| 291 | NEXUS_HdmiOutputStatus hdmiStatus; |
|---|
| 292 | rc = NEXUS_HdmiOutput_GetStatus(platformConfig.outputs.hdmi[0], &hdmiStatus); |
|---|
| 293 | /* If its connected we'll try to use compressed */ |
|---|
| 294 | if ( !rc && hdmiStatus.connected ) |
|---|
| 295 | { |
|---|
| 296 | if (( audioProgram.codec == NEXUS_AudioCodec_eAc3 ) && ( hdmiStatus.audioCodecSupported[NEXUS_AudioCodec_eAc3] )) |
|---|
| 297 | { |
|---|
| 298 | NEXUS_AudioOutput_AddInput( |
|---|
| 299 | NEXUS_HdmiOutput_GetAudioConnector(platformConfig.outputs.hdmi[0]), |
|---|
| 300 | NEXUS_AudioDecoder_GetConnector(audioPassthroughDecoder, NEXUS_AudioDecoderConnectorType_eCompressed)); |
|---|
| 301 | } |
|---|
| 302 | else |
|---|
| 303 | { |
|---|
| 304 | NEXUS_AudioOutput_AddInput( |
|---|
| 305 | NEXUS_HdmiOutput_GetAudioConnector(platformConfig.outputs.hdmi[0]), |
|---|
| 306 | NEXUS_AudioDecoder_GetConnector(audioDecoder, NEXUS_AudioDecoderConnectorType_eStereo)); |
|---|
| 307 | } |
|---|
| 308 | } |
|---|
| 309 | else |
|---|
| 310 | { |
|---|
| 311 | /* if not connected we'll default to stereo on hotplug */ |
|---|
| 312 | NEXUS_AudioOutput_AddInput( |
|---|
| 313 | NEXUS_HdmiOutput_GetAudioConnector(platformConfig.outputs.hdmi[0]), |
|---|
| 314 | NEXUS_AudioDecoder_GetConnector(audioDecoder, NEXUS_AudioDecoderConnectorType_eStereo)); |
|---|
| 315 | } |
|---|
| 316 | } |
|---|
| 317 | #endif |
|---|
| 318 | |
|---|
| 319 | NEXUS_Display_GetDefaultSettings(&displaySettings); |
|---|
| 320 | displaySettings.displayType = opts.common.displayType; |
|---|
| 321 | displaySettings.format = opts.common.displayFormat; |
|---|
| 322 | display = NEXUS_Display_Open(0, &displaySettings); |
|---|
| 323 | #if NEXUS_NUM_COMPOSITE_OUTPUTS |
|---|
| 324 | if (opts.common.useCompositeOutput) { |
|---|
| 325 | rc = NEXUS_Display_AddOutput(display, NEXUS_CompositeOutput_GetConnector(platformConfig.outputs.composite[0])); |
|---|
| 326 | BDBG_ASSERT(!rc); |
|---|
| 327 | } |
|---|
| 328 | #endif |
|---|
| 329 | #if NEXUS_NUM_COMPONENT_OUTPUTS |
|---|
| 330 | if (opts.common.useComponentOutput) { |
|---|
| 331 | rc = NEXUS_Display_AddOutput(display, NEXUS_ComponentOutput_GetConnector(platformConfig.outputs.component[0])); |
|---|
| 332 | BDBG_ASSERT(!rc); |
|---|
| 333 | } |
|---|
| 334 | #endif |
|---|
| 335 | #if NEXUS_NUM_PANEL_OUTPUTS |
|---|
| 336 | if (opts.common.usePanelOutput) { |
|---|
| 337 | rc = NEXUS_Display_AddOutput(display, NEXUS_PanelOutput_GetConnector(platformConfig.outputs.panel[0])); |
|---|
| 338 | BDBG_ASSERT(!rc); |
|---|
| 339 | NEXUS_BoardCfg_ConfigurePanel(true, true, true); |
|---|
| 340 | printf("Panel on\n"); |
|---|
| 341 | } |
|---|
| 342 | #endif |
|---|
| 343 | #if NEXUS_NUM_SCART_INPUTS |
|---|
| 344 | if (opts.common.useScart1CompositeOutput) { |
|---|
| 345 | rc = NEXUS_Display_AddOutput(display, NEXUS_ScartInput_GetVideoOutputConnector(platformConfig.inputs.scart[1])); |
|---|
| 346 | BDBG_ASSERT(!rc); |
|---|
| 347 | printf("Turning on: scart 1 composite output\n"); |
|---|
| 348 | } |
|---|
| 349 | #endif |
|---|
| 350 | #if NEXUS_NUM_HDMI_OUTPUTS |
|---|
| 351 | if (opts.common.useHdmiOutput) { |
|---|
| 352 | NEXUS_HdmiOutputSettings hdmiSettings; |
|---|
| 353 | |
|---|
| 354 | rc = NEXUS_Display_AddOutput(display, NEXUS_HdmiOutput_GetVideoConnector(platformConfig.outputs.hdmi[0])); |
|---|
| 355 | BDBG_ASSERT(!rc); |
|---|
| 356 | |
|---|
| 357 | /* Install hotplug callback -- video only for now */ |
|---|
| 358 | NEXUS_HdmiOutput_GetSettings(platformConfig.outputs.hdmi[0], &hdmiSettings); |
|---|
| 359 | hdmiSettings.hotplugCallback.callback = hotplug_callback; |
|---|
| 360 | hdmiSettings.hotplugCallback.context = platformConfig.outputs.hdmi[0]; |
|---|
| 361 | hdmiSettings.hotplugCallback.param = (int)display; |
|---|
| 362 | NEXUS_HdmiOutput_SetSettings(platformConfig.outputs.hdmi[0], &hdmiSettings); |
|---|
| 363 | |
|---|
| 364 | /* Force a hotplug to switch to preferred format */ |
|---|
| 365 | hotplug_callback(platformConfig.outputs.hdmi[0], (int)display); |
|---|
| 366 | } |
|---|
| 367 | #endif |
|---|
| 368 | |
|---|
| 369 | if (opts.graphics) { |
|---|
| 370 | NEXUS_SurfaceHandle framebuffer; |
|---|
| 371 | NEXUS_SurfaceCreateSettings surfaceCreateSettings; |
|---|
| 372 | NEXUS_SurfaceMemory mem; |
|---|
| 373 | NEXUS_GraphicsSettings graphicsSettings; |
|---|
| 374 | NEXUS_VideoFormatInfo videoFormatInfo; |
|---|
| 375 | unsigned i,j; |
|---|
| 376 | |
|---|
| 377 | NEXUS_VideoFormat_GetInfo(displaySettings.format, &videoFormatInfo); |
|---|
| 378 | |
|---|
| 379 | NEXUS_Surface_GetDefaultCreateSettings(&surfaceCreateSettings); |
|---|
| 380 | surfaceCreateSettings.width = 720; |
|---|
| 381 | surfaceCreateSettings.height = videoFormatInfo.height; |
|---|
| 382 | framebuffer = NEXUS_Surface_Create(&surfaceCreateSettings); |
|---|
| 383 | NEXUS_Surface_GetMemory(framebuffer, &mem); |
|---|
| 384 | for (i=0;i<surfaceCreateSettings.height;i++) { |
|---|
| 385 | for (j=0;j<surfaceCreateSettings.width;j++) { |
|---|
| 386 | /* create checker board */ |
|---|
| 387 | ((uint32_t*)((uint8_t*)mem.buffer + i*mem.pitch))[j] = (((i/50)%2) ^ ((j/50)%2)) ? 0x00000000 : 0xFFFFFFFF; |
|---|
| 388 | } |
|---|
| 389 | } |
|---|
| 390 | |
|---|
| 391 | NEXUS_Display_GetGraphicsSettings(display, &graphicsSettings); |
|---|
| 392 | graphicsSettings.enabled = true; |
|---|
| 393 | graphicsSettings.clip.width = surfaceCreateSettings.width; |
|---|
| 394 | graphicsSettings.clip.height = surfaceCreateSettings.height; |
|---|
| 395 | rc = NEXUS_Display_SetGraphicsSettings(display, &graphicsSettings); |
|---|
| 396 | BDBG_ASSERT(!rc); |
|---|
| 397 | rc = NEXUS_Display_SetGraphicsFramebuffer(display, framebuffer); |
|---|
| 398 | BDBG_ASSERT(!rc); |
|---|
| 399 | } |
|---|
| 400 | |
|---|
| 401 | window = NEXUS_VideoWindow_Open(display, 0); |
|---|
| 402 | |
|---|
| 403 | NEXUS_VideoWindow_GetSettings(window, &windowSettings); |
|---|
| 404 | windowSettings.contentMode = opts.common.contentMode; |
|---|
| 405 | rc = NEXUS_VideoWindow_SetSettings(window, &windowSettings); |
|---|
| 406 | BDBG_ASSERT(!rc); |
|---|
| 407 | |
|---|
| 408 | /* bring up decoder and connect to display */ |
|---|
| 409 | videoDecoder = NEXUS_VideoDecoder_Open(opts.common.videoDecoder, NULL); /* take default capabilities */ |
|---|
| 410 | rc = NEXUS_VideoWindow_AddInput(window, NEXUS_VideoDecoder_GetConnector(videoDecoder)); |
|---|
| 411 | BDBG_ASSERT(!rc); |
|---|
| 412 | |
|---|
| 413 | NEXUS_Display_GetVbiSettings(display, &displayVbiSettings); |
|---|
| 414 | displayVbiSettings.vbiSource = NEXUS_VideoDecoder_GetConnector(videoDecoder); |
|---|
| 415 | displayVbiSettings.closedCaptionEnabled = opts.closedCaptionEnabled; |
|---|
| 416 | displayVbiSettings.closedCaptionRouting = opts.closedCaptionEnabled; |
|---|
| 417 | rc = NEXUS_Display_SetVbiSettings(display, &displayVbiSettings); |
|---|
| 418 | BDBG_ASSERT(!rc); |
|---|
| 419 | |
|---|
| 420 | #if NEXUS_HAS_ASTM |
|---|
| 421 | if (opts.astm) { |
|---|
| 422 | /* create an astm instance and connect */ |
|---|
| 423 | NEXUS_Astm_GetDefaultSettings(&astmSettings); |
|---|
| 424 | astmSettings.stcChannel = stcChannel; |
|---|
| 425 | astmSettings.videoDecoder = videoDecoder; |
|---|
| 426 | astmSettings.audioDecoder[0] = audioDecoder; |
|---|
| 427 | astmSettings.audioDecoder[1] = audioPassthroughDecoder; |
|---|
| 428 | astmSettings.stcMaster = audioDecoder; /* audio master is preferred */ |
|---|
| 429 | astm = NEXUS_Astm_Create(&astmSettings); |
|---|
| 430 | } |
|---|
| 431 | #endif |
|---|
| 432 | |
|---|
| 433 | #if NEXUS_HAS_SYNC_CHANNEL |
|---|
| 434 | if (opts.sync) { |
|---|
| 435 | NEXUS_SyncChannel_GetSettings(syncChannel, &syncChannelSettings); |
|---|
| 436 | syncChannelSettings.videoInput = NEXUS_VideoDecoder_GetConnector(videoDecoder); |
|---|
| 437 | syncChannelSettings.audioInput[0] = NEXUS_AudioDecoder_GetConnector(audioDecoder, NEXUS_AudioDecoderConnectorType_eStereo); |
|---|
| 438 | rc = NEXUS_SyncChannel_SetSettings(syncChannel, &syncChannelSettings); |
|---|
| 439 | BDBG_ASSERT(!rc); |
|---|
| 440 | } |
|---|
| 441 | #endif |
|---|
| 442 | |
|---|
| 443 | /* Start Decoders */ |
|---|
| 444 | start = b_get_time(); |
|---|
| 445 | if (opts.common.videoPid) { |
|---|
| 446 | rc = NEXUS_VideoDecoder_Start(videoDecoder, &videoProgram); |
|---|
| 447 | BDBG_ASSERT(!rc); |
|---|
| 448 | } |
|---|
| 449 | if (opts.common.audioPid) { |
|---|
| 450 | rc = NEXUS_AudioDecoder_Start(audioDecoder, &audioProgram); |
|---|
| 451 | BDBG_ASSERT(!rc); |
|---|
| 452 | rc = NEXUS_AudioDecoder_Start(audioPassthroughDecoder, &audioProgram); |
|---|
| 453 | BDBG_ASSERT(!rc); |
|---|
| 454 | } |
|---|
| 455 | |
|---|
| 456 | #if NEXUS_HAS_ASTM |
|---|
| 457 | if (opts.astm) { |
|---|
| 458 | NEXUS_Astm_Start(astm); |
|---|
| 459 | } |
|---|
| 460 | #endif |
|---|
| 461 | |
|---|
| 462 | #if 1 |
|---|
| 463 | /* Print status while decoding */ |
|---|
| 464 | for (;;) { |
|---|
| 465 | NEXUS_VideoDecoderStatus status; |
|---|
| 466 | NEXUS_AudioDecoderStatus audioStatus; |
|---|
| 467 | uint32_t stc; |
|---|
| 468 | unsigned duration = (b_get_time() - start) / 1000; |
|---|
| 469 | unsigned bitrate = 0; |
|---|
| 470 | |
|---|
| 471 | NEXUS_VideoDecoder_GetStatus(videoDecoder, &status); |
|---|
| 472 | if (duration) { |
|---|
| 473 | bitrate = status.numBytesDecoded/duration*8; /* bps */ |
|---|
| 474 | } |
|---|
| 475 | NEXUS_StcChannel_GetStc(videoProgram.stcChannel, &stc); |
|---|
| 476 | printf("decode %.4dx%.4d, pts %#x, stc %#x (diff %d) fifo=%d%% %d.%01dMbps\n", |
|---|
| 477 | status.source.width, status.source.height, status.pts, stc, status.ptsStcDifference, status.fifoSize?(status.fifoDepth*100)/status.fifoSize:0, |
|---|
| 478 | #define MEGABYTE (1024*1024) |
|---|
| 479 | bitrate/MEGABYTE,(bitrate%MEGABYTE)*10/MEGABYTE); |
|---|
| 480 | NEXUS_AudioDecoder_GetStatus(audioDecoder, &audioStatus); |
|---|
| 481 | printf("audio0 pts %#x, stc %#x (diff %d) fifo=%d%%\n", |
|---|
| 482 | audioStatus.pts, stc, audioStatus.ptsStcDifference, audioStatus.fifoSize?(audioStatus.fifoDepth*100)/audioStatus.fifoSize:0); |
|---|
| 483 | BKNI_Sleep(1000); |
|---|
| 484 | } |
|---|
| 485 | #else |
|---|
| 486 | printf("Press ENTER to stop decode\n"); |
|---|
| 487 | getchar(); |
|---|
| 488 | |
|---|
| 489 | /* example shutdown */ |
|---|
| 490 | NEXUS_AudioDecoder_Close(audioDecoder); |
|---|
| 491 | NEXUS_VideoWindow_Close(window); |
|---|
| 492 | NEXUS_Display_Close(display); |
|---|
| 493 | NEXUS_VideoDecoder_Close(videoDecoder); |
|---|
| 494 | NEXUS_StcChannel_Close(stcChannel); |
|---|
| 495 | NEXUS_PidChannel_Close(videoPidChannel); |
|---|
| 496 | NEXUS_PidChannel_Close(audioPidChannel); |
|---|
| 497 | NEXUS_Platform_Uninit(); |
|---|
| 498 | #endif |
|---|
| 499 | |
|---|
| 500 | return 0; |
|---|
| 501 | } |
|---|
| 502 | |
|---|
| 503 | /* |
|---|
| 504 | ************************************************ |
|---|
| 505 | |
|---|
| 506 | examples / test cases |
|---|
| 507 | |
|---|
| 508 | # basic decode of streamer input |
|---|
| 509 | nexus decode -video 0x31 -audio 0x34 -video_type mpeg -audio_type ac3 |
|---|
| 510 | |
|---|
| 511 | ************************************************ |
|---|
| 512 | */ |
|---|
| 513 | |
|---|