close Warning: Can't use blame annotator:
No changeset 2 in the repository

source: svn/newcon3bcm2_21bu/nexus/utils/video.c @ 76

Last change on this file since 76 was 76, checked in by megakiss, 10 years ago

1W 대기전력을 만족시키기 위하여 POWEROFF시 튜너를 Standby 상태로 함

  • Property svn:executable set to *
File size: 23.3 KB
RevLine 
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: video.c $
39 * $brcm_Revision: 11 $
40 * $brcm_Date: 1/31/12 5:07p $
41 *
42 * Module Description:
43 *
44 * Revision History:
45 *
46 * $brcm_Log: /nexus/utils/video.c $
47 *
48 * 11   1/31/12 5:07p rjlewis
49 * SW7425-1136: Added HDMI support (and some cleanup).
50 *
51 * 10   3/23/11 5:41p vsilyaev
52 * SW7422-406: Unified parsing of command line parameters
53 *
54 * 9   3/4/11 12:40p erickson
55 * SW7420-1560: adapt to NEXUS_CalculateVideoWindowPosition change
56 *
57 * 8   3/11/10 5:26p pntruong
58 * SW3548-2717: Saved some of the useful changes from other debug.
59 *
60 * 7   2/4/10 3:29p erickson
61 * SW3548-2735: add more options
62 *
63 * 6   1/21/10 10:25a erickson
64 * SW3548-2705: set useDynamicDefaults=true for analog sources
65 *
66 * 5   1/20/10 5:11p erickson
67 * SW3548-2705: fix settop
68 *
69 * 4   1/20/10 1:41p erickson
70 * SW3548-2705: use NEXUS_AnalogVideoDecoder_GetDynamicDefaultSettings for
71 *  analog inputs
72 *
73 * 3   11/2/09 2:50p erickson
74 * SW3548-2574: use right #define
75 *
76 * 2   10/27/09 5:26p erickson
77 * SW3548-2574: fix settop
78 *
79 * 1   10/27/09 4:27p erickson
80 * SW3548-2574: check in video.c
81 *
82******************************************************************************/
83
84#include "nexus_platform.h"
85#include "nexus_pid_channel.h"
86#include "nexus_parser_band.h"
87#include "nexus_video_decoder.h"
88#include "nexus_stc_channel.h"
89#include "nexus_display.h"
90#include "nexus_video_window.h"
91#include "nexus_video_adj.h"
92#if NEXUS_NUM_ANALOG_VIDEO_DECODERS
93#include "nexus_analog_video_decoder.h"
94#endif
95#if NEXUS_HAS_HDMI_INPUT
96#include "nexus_hdmi_input.h"
97#endif
98#include "nexus_composite_output.h"
99#include "nexus_component_output.h"
100#if NEXUS_HAS_HDMI_OUTPUT
101#include "nexus_hdmi_output.h"
102#endif
103#include "nexus_surface.h"
104#include "nexus_core_utils.h"
105
106#include "bstd.h"
107#include "bkni.h"
108#include <stdio.h>
109#include <stdlib.h>
110#include <string.h>
111
112#include "cmdline_args.h"
113
114BDBG_MODULE(video);
115
116#if NEXUS_NUM_ANALOG_VIDEO_DECODERS
117static void set_analog_input(NEXUS_AnalogVideoDecoderHandle analogVideoDecoder, NEXUS_VideoInput videoInput);
118#endif
119#if NEXUS_NUM_HDMI_OUTPUTS
120static void hotplug_callback(void *pParam, int iParam);
121#endif
122
123int main(int argc, const char *argv[])
124{
125    NEXUS_PlatformSettings platformSettings;
126    NEXUS_PlatformConfiguration platformConfig;
127    NEXUS_InputBand inputBand;
128    NEXUS_ParserBand parserBand;
129    NEXUS_ParserBandSettings parserBandSettings;
130    NEXUS_StcChannelHandle stcChannel;
131    NEXUS_StcChannelSettings stcSettings;
132    NEXUS_PidChannelHandle pcrPidChannel, videoPidChannel;
133    NEXUS_DisplayHandle display;
134    NEXUS_DisplaySettings displaySettings;
135    NEXUS_VideoWindowHandle window;
136    NEXUS_VideoWindowSettings windowSettings;
137    NEXUS_VideoDecoderHandle videoDecoder;
138    NEXUS_VideoDecoderStartSettings videoProgram;
139    struct util_opts_t opts;
140    NEXUS_Error rc;
141    bool is_digital = false;
142    NEXUS_VideoInput videoInput;
143#if NEXUS_NUM_ANALOG_VIDEO_DECODERS
144    NEXUS_AnalogVideoDecoderHandle analogVideoDecoder;
145#endif
146#if NEXUS_NUM_HDMI_INPUTS > 0
147    NEXUS_HdmiInputHandle hdmi0;
148#endif
149#if NEXUS_NUM_HDMI_INPUTS > 1
150    NEXUS_HdmiInputHandle hdmi1;
151#endif
152    NEXUS_VideoFormatInfo displayFormatInfo;
153
154    if (cmdline_parse(argc, argv, &opts)) {
155        return 0;
156    }
157    if (cmdline_probe(&opts.common, opts.filename, &opts.indexname)) {
158        return 1;
159    }
160
161    /* Bring up all modules for a platform in a default configuration for this platform */
162    NEXUS_Platform_GetDefaultSettings(&platformSettings);
163    platformSettings.openFrontend = false;
164    rc = NEXUS_Platform_Init(&platformSettings);
165    BDBG_ASSERT(!rc);
166    NEXUS_Platform_GetConfiguration(&platformConfig);
167
168    /* Get the streamer input band from Platform. Platform has already configured the FPGA with a default streamer routing */
169    rc = NEXUS_Platform_GetStreamerInputBand(0, &inputBand);
170    BDBG_ASSERT(!rc);
171
172    /* Map a parser band to the streamer input band */
173    parserBand = NEXUS_ParserBand_e0;
174    NEXUS_ParserBand_GetSettings(parserBand, &parserBandSettings);
175    parserBandSettings.sourceType = NEXUS_ParserBandSourceType_eInputBand;
176    parserBandSettings.sourceTypeSettings.inputBand = inputBand;
177    parserBandSettings.transportType = opts.common.transportType;
178    rc = NEXUS_ParserBand_SetSettings(parserBand, &parserBandSettings);
179    BDBG_ASSERT(!rc);
180
181    /* Open the audio and video pid channels */
182    pcrPidChannel = NEXUS_PidChannel_Open(parserBand, opts.common.pcrPid?opts.common.pcrPid:opts.common.videoPid, NULL);
183    videoPidChannel = NEXUS_PidChannel_Open(parserBand, opts.common.videoPid, NULL);
184
185    /* Open the StcChannel to do lipsync with the PCR */
186    NEXUS_StcChannel_GetDefaultSettings(0, &stcSettings);
187    stcSettings.timebase = NEXUS_Timebase_e0;
188    stcSettings.mode = NEXUS_StcChannelMode_ePcr; /* live */
189    stcSettings.modeSettings.pcr.pidChannel = pcrPidChannel;
190    stcChannel = NEXUS_StcChannel_Open(0, &stcSettings);
191
192    NEXUS_VideoDecoder_GetDefaultStartSettings(&videoProgram);
193    videoProgram.codec = opts.common.videoCodec;
194    videoProgram.pidChannel = videoPidChannel;
195    videoProgram.stcChannel = stcChannel;
196    videoProgram.frameRate = opts.common.videoFrameRate;
197    videoProgram.aspectRatio = opts.common.aspectRatio;
198    videoProgram.sampleAspectRatio.x = opts.common.sampleAspectRatio.x;
199    videoProgram.sampleAspectRatio.y = opts.common.sampleAspectRatio.y;
200
201    NEXUS_Display_GetDefaultSettings(&displaySettings);
202    display = NEXUS_Display_Open(0, &displaySettings);
203    NEXUS_VideoFormat_GetInfo(displaySettings.format, &displayFormatInfo);
204
205#if NEXUS_NUM_COMPOSITE_OUTPUTS
206    if (opts.common.useCompositeOutput) {
207        rc = NEXUS_Display_AddOutput(display, NEXUS_CompositeOutput_GetConnector(platformConfig.outputs.composite[0]));
208        BDBG_ASSERT(!rc);
209    }
210#endif
211#if NEXUS_NUM_COMPONENT_OUTPUTS
212    if (opts.common.useComponentOutput) {
213        rc = NEXUS_Display_AddOutput(display, NEXUS_ComponentOutput_GetConnector(platformConfig.outputs.component[0]));
214        BDBG_ASSERT(!rc);
215    }
216#endif
217#if NEXUS_NUM_PANEL_OUTPUTS
218    if (opts.common.usePanelOutput) {
219        rc = NEXUS_Display_AddOutput(display, NEXUS_PanelOutput_GetConnector(platformConfig.outputs.panel[0]));
220        BDBG_ASSERT(!rc);
221        NEXUS_BoardCfg_ConfigurePanel(true, true, true);
222        printf("Panel on\n");
223    }
224#endif
225#if NEXUS_NUM_SCART_INPUTS
226    if (opts.common.useScart1CompositeOutput) {
227        rc = NEXUS_Display_AddOutput(display, NEXUS_ScartInput_GetVideoOutputConnector(platformConfig.inputs.scart[1]));
228        BDBG_ASSERT(!rc);
229        printf("Turning on: scart 1 composite output\n");
230    }
231#endif
232#if NEXUS_NUM_HDMI_INPUTS > 0
233    hdmi0 = NEXUS_HdmiInput_Open(0, NULL);
234#endif
235#if NEXUS_NUM_HDMI_INPUTS > 1
236    hdmi1 = NEXUS_HdmiInput_Open(1, NULL);
237#endif
238
239#if NEXUS_NUM_HDMI_OUTPUTS
240    if (opts.common.useHdmiOutput) {
241        NEXUS_HdmiOutputSettings hdmiSettings;
242
243        rc = NEXUS_Display_AddOutput(display, NEXUS_HdmiOutput_GetVideoConnector(platformConfig.outputs.hdmi[0]));
244        BDBG_ASSERT(!rc);
245
246        /* Install hotplug callback -- video only for now */
247        NEXUS_HdmiOutput_GetSettings(platformConfig.outputs.hdmi[0], &hdmiSettings);
248        hdmiSettings.hotplugCallback.callback = hotplug_callback;
249        hdmiSettings.hotplugCallback.context = platformConfig.outputs.hdmi[0];
250        hdmiSettings.hotplugCallback.param = (int)display;
251        NEXUS_HdmiOutput_SetSettings(platformConfig.outputs.hdmi[0], &hdmiSettings);
252
253       /* Force a hotplug to switch to preferred format */
254       hotplug_callback(platformConfig.outputs.hdmi[0], (int)display);
255    }
256#endif
257
258    if (opts.graphics) {
259        NEXUS_SurfaceHandle framebuffer;
260        NEXUS_SurfaceCreateSettings surfaceCreateSettings;
261        NEXUS_SurfaceMemory mem;
262        NEXUS_GraphicsSettings graphicsSettings;
263        unsigned i,j;
264
265        NEXUS_Surface_GetDefaultCreateSettings(&surfaceCreateSettings);
266        surfaceCreateSettings.width = 720;
267        surfaceCreateSettings.height = displayFormatInfo.height;
268        framebuffer = NEXUS_Surface_Create(&surfaceCreateSettings);
269        NEXUS_Surface_GetMemory(framebuffer, &mem);
270        for (i=0;i<surfaceCreateSettings.height;i++) {
271            for (j=0;j<surfaceCreateSettings.width;j++) {
272                /* create checker board */
273                ((uint32_t*)((uint8_t*)mem.buffer + i*mem.pitch))[j] = (((i/50)%2) ^ ((j/50)%2)) ? 0x00000000 : 0xFFFFFFFF;
274            }
275        }
276
277        NEXUS_Display_GetGraphicsSettings(display, &graphicsSettings);
278        graphicsSettings.enabled = true;
279        graphicsSettings.clip.width = surfaceCreateSettings.width;
280        graphicsSettings.clip.height = surfaceCreateSettings.height;
281        rc = NEXUS_Display_SetGraphicsSettings(display, &graphicsSettings);
282        BDBG_ASSERT(!rc);
283        rc = NEXUS_Display_SetGraphicsFramebuffer(display, framebuffer);
284        BDBG_ASSERT(!rc);
285    }
286
287    window = NEXUS_VideoWindow_Open(display, 0);
288
289    NEXUS_VideoWindow_GetSettings(window, &windowSettings);
290    windowSettings.contentMode = opts.common.contentMode;
291    rc = NEXUS_VideoWindow_SetSettings(window, &windowSettings);
292    BDBG_ASSERT(!rc);
293
294    /* bring up decoder and connect to display */
295    videoDecoder = NEXUS_VideoDecoder_Open(0, NULL); /* take default capabilities */
296
297#if NEXUS_NUM_ANALOG_VIDEO_DECODERS
298    analogVideoDecoder = NEXUS_AnalogVideoDecoder_Open(0, NULL);
299#endif
300
301    while (1)
302    {
303        char buf[256];
304        int x, y, width, height;
305
306        printf("video>"); fflush(stdout);
307        fgets(buf, 256, stdin);
308        buf[strlen(buf)-1] = 0; /* chop off \n */
309
310        NEXUS_VideoWindow_GetSettings(window, &windowSettings);
311
312        if (strstr(buf, "help") || !strcmp(buf, "?")) {
313            printf(
314            "Commands:\n"
315            "  input(cvbs0|cvbs1|svideo0|svideo1|component0|component1|hdmi0|hdmi1|digital|vga)\n"
316            "  position(x,y,width,height)\n"
317            "  clip(clipRect.x,clipRect.y,clipRect.width,clipRect.height [,baseRect.width,baseRect.height])\n"
318            "  clip%%(horz %%, vert %%) - floating point supported\n"
319            "  contentMode(box|zoom|full)\n"
320            "  autopq(true|false)\n"
321            "  visible(true|false)\n"
322            "  cti(x)\n"
323            "  q - quit\n"
324            );
325        }
326        else if (strstr(buf, "quit") || !strcmp(buf, "q")) {
327            break;
328        }
329        else if (strstr(buf, "autopq")) {
330            rc = NEXUS_DisplayModule_SetAutomaticPictureQuality();
331            if (rc) BERR_TRACE(rc);
332        }
333        else if (strstr(buf, "cti(")) {
334            rc = sscanf(&buf[4], "%d", &x);
335            if (rc == 1) {
336                NEXUS_VideoWindowCoefficientIndexSettings ctiSettings;
337                NEXUS_VideoWindow_GetCoefficientIndexSettings(window, &ctiSettings);
338                ctiSettings.sclHorzLuma    = x;
339                ctiSettings.sclVertLuma    = x;
340                ctiSettings.sclHorzChroma  = x;
341                ctiSettings.sclVertChroma  = x;
342                ctiSettings.hsclHorzLuma   = x;
343                ctiSettings.hsclHorzChroma = x;
344                ctiSettings.madHorzLuma    = x;
345                ctiSettings.madHorzChroma  = x;
346                rc = NEXUS_VideoWindow_SetCoefficientIndexSettings(window, &ctiSettings);
347                if (rc) BERR_TRACE(rc);
348            }
349        }
350        else if (strstr(buf, "visible(")) {
351            char *input = &buf[8];
352            windowSettings.visible = input[0] == 't';
353            rc = NEXUS_VideoWindow_SetSettings(window, &windowSettings);
354            if (rc) BERR_TRACE(rc);
355        }
356        else if (strstr(buf, "position(")) {
357            rc = sscanf(&buf[9], "%d,%d,%d,%d", &x, &y, &width, &height);
358            if (rc == 4) {
359                windowSettings.position.x = x;
360                windowSettings.position.y = y;
361                windowSettings.position.width = width;
362                windowSettings.position.height = height;
363                rc = NEXUS_VideoWindow_SetSettings(window, &windowSettings);
364                if (rc) BERR_TRACE(rc);
365            }
366        }
367        else if (strstr(buf, "clip%(")) {
368            float w,h;
369            rc = sscanf(&buf[6], "%f,%f", &w, &h);
370            if (rc == 2) {
371                NEXUS_CalculateVideoWindowPositionSettings pos;
372                NEXUS_VideoWindowContentMode contentMode = windowSettings.contentMode;
373
374                NEXUS_GetDefaultCalculateVideoWindowPositionSettings(&pos);
375                pos.horizontalClipping = w * 100;
376                pos.verticalClipping = h * 100;
377                pos.viewport = windowSettings.position;
378                pos.displayWidth = displayFormatInfo.width;
379                pos.displayHeight = displayFormatInfo.height;
380                rc = NEXUS_CalculateVideoWindowPosition(&pos, &windowSettings, &windowSettings);
381                if (rc) BERR_TRACE(rc);
382
383                /* restore the contentMode. we don't support manual a/r, so don't let the helper func override */
384                windowSettings.contentMode = contentMode;
385
386                rc = NEXUS_VideoWindow_SetSettings(window, &windowSettings);
387                if (rc) BERR_TRACE(rc);
388            }
389        }
390        else if (strstr(buf, "clip(")) {
391            int base_width, base_height;
392            rc = sscanf(&buf[5], "%d,%d,%d,%d,%d,%d", &x, &y, &width, &height, &base_width, &base_height);
393            if (rc >= 4) {
394                windowSettings.clipRect.x = x;
395                windowSettings.clipRect.y = y;
396                windowSettings.clipRect.width = width;
397                windowSettings.clipRect.height = height;
398                windowSettings.clipBase.x = 0;
399                windowSettings.clipBase.y = 0;
400                if (rc > 5) {
401                    windowSettings.clipBase.width = base_width;
402                    windowSettings.clipBase.height = base_height;
403                }
404                else {
405                    windowSettings.clipBase.width = displayFormatInfo.width;
406                    windowSettings.clipBase.height = displayFormatInfo.height;
407                }
408                rc = NEXUS_VideoWindow_SetSettings(window, &windowSettings);
409                if (rc) BERR_TRACE(rc);
410            }
411        }
412        else if (strstr(buf, "contentMode(")) {
413            char *input = &buf[12];
414
415            if (strstr(input, "zoom")) {
416                windowSettings.contentMode = NEXUS_VideoWindowContentMode_eZoom;
417            }
418            else if (strstr(input, "box")) {
419                windowSettings.contentMode = NEXUS_VideoWindowContentMode_eBox;
420            }
421            else if (strstr(input, "full")) {
422                windowSettings.contentMode = NEXUS_VideoWindowContentMode_eFull;
423            }
424
425            rc = NEXUS_VideoWindow_SetSettings(window, &windowSettings);
426            if (rc) BERR_TRACE(rc);
427        }
428        else if (strstr(buf, "input(")) {
429            char *input = &buf[6];
430
431            if (is_digital) {
432                NEXUS_VideoDecoder_Stop(videoDecoder);
433            }
434            NEXUS_VideoWindow_RemoveAllInputs(window);
435            videoInput = NULL;
436            is_digital = false;
437
438            if (0) {}
439#if NEXUS_NUM_PC_INPUTS > 0
440            else if (strstr(input, "vga") ||
441                     strstr(input, "vga0")) {
442                set_analog_input(analogVideoDecoder, NEXUS_PcInput_GetConnector(platformConfig.inputs.pc[0]));
443                videoInput = NEXUS_AnalogVideoDecoder_GetConnector(analogVideoDecoder);
444            }
445#endif
446#if NEXUS_NUM_COMPOSITE_INPUTS > 0
447            else if (strstr(input, "cvbs0")) {
448                set_analog_input(analogVideoDecoder, NEXUS_CompositeInput_GetConnector(platformConfig.inputs.composite[0]));
449                videoInput = NEXUS_AnalogVideoDecoder_GetConnector(analogVideoDecoder);
450            }
451#endif
452#if NEXUS_NUM_COMPOSITE_INPUTS > 1
453            else if (strstr(input, "cvbs1")) {
454                set_analog_input(analogVideoDecoder, NEXUS_CompositeInput_GetConnector(platformConfig.inputs.composite[1]));
455                videoInput = NEXUS_AnalogVideoDecoder_GetConnector(analogVideoDecoder);
456            }
457#endif
458#if NEXUS_NUM_COMPOSITE_INPUTS > 2
459            else if (strstr(input, "cvbs2")) {
460                set_analog_input(analogVideoDecoder, NEXUS_CompositeInput_GetConnector(platformConfig.inputs.composite[2]));
461                videoInput = NEXUS_AnalogVideoDecoder_GetConnector(analogVideoDecoder);
462            }
463#endif
464#if NEXUS_NUM_SVIDEO_INPUTS > 0
465            else if (strstr(input, "svideo0")) {
466                set_analog_input(analogVideoDecoder, NEXUS_SvideoInput_GetConnector(platformConfig.inputs.svideo[0]));
467                videoInput = NEXUS_AnalogVideoDecoder_GetConnector(analogVideoDecoder);
468            }
469#endif
470#if NEXUS_NUM_SVIDEO_INPUTS > 1
471            else if (strstr(input, "svideo1")) {
472                set_analog_input(analogVideoDecoder, NEXUS_SvideoInput_GetConnector(platformConfig.inputs.svideo[1]));
473                videoInput = NEXUS_AnalogVideoDecoder_GetConnector(analogVideoDecoder);
474            }
475#endif
476#if NEXUS_NUM_COMPONENT_INPUTS > 0
477            else if (strstr(input, "component0")) {
478                set_analog_input(analogVideoDecoder, NEXUS_ComponentInput_GetConnector(platformConfig.inputs.component[0]));
479                videoInput = NEXUS_AnalogVideoDecoder_GetConnector(analogVideoDecoder);
480            }
481#endif
482#if NEXUS_NUM_COMPONENT_INPUTS > 1
483            else if (strstr(input, "component1")) {
484                set_analog_input(analogVideoDecoder, NEXUS_ComponentInput_GetConnector(platformConfig.inputs.component[1]));
485                videoInput = NEXUS_AnalogVideoDecoder_GetConnector(analogVideoDecoder);
486            }
487#endif
488#if NEXUS_NUM_HDMI_INPUTS > 0
489            else if (strstr(input, "hdmi0")) {
490                videoInput = NEXUS_HdmiInput_GetVideoConnector(hdmi0);
491            }
492#endif
493#if NEXUS_NUM_HDMI_INPUTS > 1
494            else if (strstr(input, "hdmi1")) {
495                videoInput = NEXUS_HdmiInput_GetVideoConnector(hdmi1);
496            }
497#endif
498            else if (strstr(input, "digital") || strstr(input, "digital0")) {
499                videoInput = NEXUS_VideoDecoder_GetConnector(videoDecoder);
500                is_digital = true;
501            }
502
503            if (videoInput) {
504                rc = NEXUS_VideoWindow_AddInput(window, videoInput);
505                if (rc) BERR_TRACE(rc);
506            }
507
508            if (is_digital) {
509                rc = NEXUS_VideoDecoder_Start(videoDecoder, &videoProgram);
510                BDBG_ASSERT(!rc);
511            }
512        }
513        else if (!*buf) {
514            /* allow blank line */
515        }
516        else {
517            printf("unknown command: '%s' (use 'help' for list)\n", buf);
518            continue;
519        }
520    }
521
522    return 0;
523}
524
525#if NEXUS_NUM_HDMI_OUTPUTS
526/* registered HDMI hotplug handler -- changes the format (to monitor's default) if monitor doesn't support current format */
527static void hotplug_callback(void *pParam, int iParam)
528{
529    NEXUS_HdmiOutputStatus hdmiStatus;
530    NEXUS_HdmiOutputHandle hdmi = pParam;
531    NEXUS_DisplayHandle display = (NEXUS_DisplayHandle)iParam;
532    NEXUS_Error rc;
533
534    rc = NEXUS_HdmiOutput_GetStatus(hdmi, &hdmiStatus);
535    /*fprintf(stderr, "HDMI event: %s\n", hdmiStatus.connected?"connected":"not connected");*/
536
537    /* the app can choose to switch to the preferred format, but it's not required. */
538    if ( !rc && hdmiStatus.connected )
539    {
540        NEXUS_DisplaySettings displaySettings;
541        NEXUS_Display_GetSettings(display, &displaySettings);
542        if ( !hdmiStatus.videoFormatSupported[displaySettings.format] )
543        {
544            fprintf(stderr, "Current format not supported by attached monitor -- switching to preferred format %d\n", hdmiStatus.preferredVideoFormat);
545            if (hdmiStatus.preferredVideoFormat >= NEXUS_VideoFormat_e480p) 
546                fprintf(stderr, "Warning: This format may disable composite output!\n");
547            displaySettings.format = hdmiStatus.preferredVideoFormat;
548            NEXUS_Display_SetSettings(display, &displaySettings);
549        }
550    }
551}
552#endif
553
554#if NEXUS_NUM_ANALOG_VIDEO_DECODERS
555static void set_analog_input(NEXUS_AnalogVideoDecoderHandle analogVideoDecoder, NEXUS_VideoInput videoInput)
556{
557    NEXUS_AnalogVideoDecoderSettings analogVideoDecoderSettings;
558    NEXUS_Error rc;
559
560    /* set the input first. this allows VDC to figure out the source and recommend defaults.
561    NEXUS_AnalogVideoDecoder is not connected to the window, so no transitional effects are seen. */
562    NEXUS_AnalogVideoDecoder_GetDefaultSettings(&analogVideoDecoderSettings);
563    analogVideoDecoderSettings.input = videoInput;
564    rc = NEXUS_AnalogVideoDecoder_SetSettings(analogVideoDecoder, &analogVideoDecoderSettings);
565    BDBG_ASSERT(!rc);
566
567    /* now get the recommended defaults and apply them */
568    NEXUS_AnalogVideoDecoder_GetDynamicDefaultSettings(analogVideoDecoder, &analogVideoDecoderSettings);
569    /* user could customize here */
570    analogVideoDecoderSettings.useDynamicDefaults = true; /* but, for now, just use all internal defaults */
571    rc = NEXUS_AnalogVideoDecoder_SetSettings(analogVideoDecoder, &analogVideoDecoderSettings);
572    BDBG_ASSERT(!rc);
573}
574#endif
575
576/*
577************************************************
578
579examples / test cases
580
581# basic decode of external input
582nexus video
583
584************************************************
585*/
Note: See TracBrowser for help on using the repository browser.