-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathdecode.c
executable file
·208 lines (190 loc) · 8.49 KB
/
decode.c
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
#include "nexus_platform.h"
#include "nexus_pid_channel.h"
#include "nexus_parser_band.h"
#include "nexus_video_decoder.h"
#include "nexus_stc_channel.h"
#include "nexus_display.h"
#include "nexus_video_window.h"
#include "nexus_video_input.h"
#include "nexus_audio_dac.h"
#include "nexus_audio_decoder.h"
#include "nexus_audio_output.h"
#include "nexus_audio_input.h"
#include "nexus_spdif_output.h"
#include "nexus_composite_output.h"
#include "nexus_component_output.h"
#define NEXUS_HAS_HDMI_OUTPUTS 1
#define NEXUS_NUM_HDMI_OUTPUTS 1
#if NEXUS_HAS_HDMI_OUTPUTS
#include "nexus_hdmi_output.h"
#endif
#include "bstd.h"
#include "bkni.h"
#include <stdio.h>
#include <stdlib.h>
/* the following define the input file and its characteristics -- these will vary by input file */
#define TRANSPORT_TYPE NEXUS_TransportType_eTs
#define VIDEO_CODEC NEXUS_VideoCodec_eH264
#define AUDIO_CODEC NEXUS_AudioCodec_eAc3
#define VIDEO_PID 289
#define AUDIO_PID 290
int main(void)
{
NEXUS_PlatformSettings platformSettings;
NEXUS_PlatformConfiguration platformConfig;
NEXUS_InputBand inputBand;
NEXUS_ParserBand parserBand;
NEXUS_ParserBandSettings parserBandSettings;
NEXUS_StcChannelHandle stcChannel;
NEXUS_StcChannelSettings stcSettings;
NEXUS_PidChannelHandle videoPidChannel, audioPidChannel;
NEXUS_DisplayHandle display;
NEXUS_DisplaySettings displaySettings;
NEXUS_VideoWindowHandle window;
NEXUS_VideoDecoderHandle vdecode;
NEXUS_VideoDecoderStartSettings videoProgram;
NEXUS_AudioDecoderHandle pcmDecoder, compressedDecoder;
NEXUS_AudioDecoderStartSettings audioProgram;
#if NEXUS_NUM_HDMI_OUTPUTS
NEXUS_HdmiOutputStatus hdmiStatus;
NEXUS_Error rc;
#endif
/* Bring up all modules for a platform in a default configuration for this platform */
NEXUS_Platform_GetDefaultSettings(&platformSettings);
platformSettings.openFrontend = false;
NEXUS_Platform_Init(&platformSettings);
NEXUS_Platform_GetConfiguration(&platformConfig);
/* Get the streamer input band from Platform. Platform has already configured the FPGA with a default streamer routing */
NEXUS_Platform_GetStreamerInputBand(0, &inputBand);
/* Map a parser band to the streamer input band. */
parserBand = NEXUS_ParserBand_e0;
NEXUS_ParserBand_GetSettings(parserBand, &parserBandSettings);
parserBandSettings.sourceType = NEXUS_ParserBandSourceType_eInputBand;
parserBandSettings.sourceTypeSettings.inputBand = inputBand;
parserBandSettings.transportType = TRANSPORT_TYPE;
NEXUS_ParserBand_SetSettings(parserBand, &parserBandSettings);
/* Open the audio and video pid channels */
videoPidChannel = NEXUS_PidChannel_Open(parserBand, VIDEO_PID, NULL);
audioPidChannel = NEXUS_PidChannel_Open(parserBand, AUDIO_PID, NULL);
/* Open the StcChannel to do lipsync with the PCR */
NEXUS_StcChannel_GetDefaultSettings(0, &stcSettings);
stcSettings.timebase = NEXUS_Timebase_e0;
stcSettings.mode = NEXUS_StcChannelMode_ePcr; /* live */
stcSettings.modeSettings.pcr.pidChannel = videoPidChannel; /* PCR happens to be on video pid */
stcChannel = NEXUS_StcChannel_Open(0, &stcSettings);
/* Set up decoder Start structures now. We need to know the audio codec to properly set up
the audio outputs. */
NEXUS_VideoDecoder_GetDefaultStartSettings(&videoProgram);
videoProgram.codec = VIDEO_CODEC;
videoProgram.pidChannel = videoPidChannel;
videoProgram.stcChannel = stcChannel;
NEXUS_AudioDecoder_GetDefaultStartSettings(&audioProgram);
audioProgram.codec = AUDIO_CODEC;
audioProgram.pidChannel = audioPidChannel;
audioProgram.stcChannel = stcChannel;
/* Bring up audio decoders and outputs */
pcmDecoder = NEXUS_AudioDecoder_Open(0, NULL);
compressedDecoder = NEXUS_AudioDecoder_Open(1, NULL);
NEXUS_AudioOutput_AddInput(
NEXUS_AudioDac_GetConnector(platformConfig.outputs.audioDacs[0]),
NEXUS_AudioDecoder_GetConnector(pcmDecoder, NEXUS_AudioDecoderConnectorType_eStereo));
if ( audioProgram.codec == NEXUS_AudioCodec_eAc3 )
{
/* Only pass through AC3 */
NEXUS_AudioOutput_AddInput(
NEXUS_SpdifOutput_GetConnector(platformConfig.outputs.spdif[0]),
NEXUS_AudioDecoder_GetConnector(compressedDecoder, NEXUS_AudioDecoderConnectorType_eCompressed));
}
else
{
NEXUS_AudioOutput_AddInput(
NEXUS_SpdifOutput_GetConnector(platformConfig.outputs.spdif[0]),
NEXUS_AudioDecoder_GetConnector(pcmDecoder, NEXUS_AudioDecoderConnectorType_eStereo));
}
#if NEXUS_NUM_HDMI_OUTPUTS
NEXUS_AudioOutput_AddInput(
NEXUS_HdmiOutput_GetAudioConnector(platformConfig.outputs.hdmi[0]),
NEXUS_AudioDecoder_GetConnector(pcmDecoder, NEXUS_AudioDecoderConnectorType_eStereo));
#endif
/* Bring up display and outputs */
NEXUS_Display_GetDefaultSettings(&displaySettings);
displaySettings.format = NEXUS_VideoFormat_eNtsc;
display = NEXUS_Display_Open(0, &displaySettings);
#if NEXUS_NUM_COMPONENT_OUTPUTS
NEXUS_Display_AddOutput(display, NEXUS_ComponentOutput_GetConnector(platformConfig.outputs.component[0]));
#endif
#if NEXUS_NUM_COMPOSITE_OUTPUTS
NEXUS_Display_AddOutput(display, NEXUS_CompositeOutput_GetConnector(platformConfig.outputs.composite[0]));
#endif
#if NEXUS_NUM_SVIDEO_OUTPUTS
NEXUS_Display_AddOutput(display, NEXUS_SvideoOutput_GetConnector(platformConfig.outputs.svideo[0]));
#endif
#if NEXUS_NUM_HDMI_OUTPUTS
NEXUS_Display_AddOutput(display, NEXUS_HdmiOutput_GetVideoConnector(platformConfig.outputs.hdmi[0]));
rc = NEXUS_HdmiOutput_GetStatus(platformConfig.outputs.hdmi[0], &hdmiStatus);
if ( !rc && hdmiStatus.connected )
{
/* If current display format is not supported by monitor, switch to monitor's preferred format.
If other connected outputs do not support the preferred format, a harmless error will occur. */
NEXUS_Display_GetSettings(display, &displaySettings);
if ( !hdmiStatus.videoFormatSupported[displaySettings.format] ) {
displaySettings.format = hdmiStatus.preferredVideoFormat;
NEXUS_Display_SetSettings(display, &displaySettings);
}
}
#endif
window = NEXUS_VideoWindow_Open(display, 0);
/* bring up decoder and connect to display */
vdecode = NEXUS_VideoDecoder_Open(0, NULL); /* take default capabilities */
NEXUS_VideoWindow_AddInput(window, NEXUS_VideoDecoder_GetConnector(vdecode));
/* Start Decoders */
NEXUS_VideoDecoder_Start(vdecode, &videoProgram);
NEXUS_AudioDecoder_Start(pcmDecoder, &audioProgram);
if ( audioProgram.codec == NEXUS_AudioCodec_eAc3 )
{
/* Only pass through AC3 */
NEXUS_AudioDecoder_Start(compressedDecoder, &audioProgram);
}
#if 0
/* Print status while decoding */
for (;;) {
NEXUS_VideoDecoderStatus status;
NEXUS_AudioDecoderStatus audioStatus;
uint32_t stc;
NEXUS_VideoDecoder_GetStatus(vdecode, &status);
NEXUS_StcChannel_GetStc(videoProgram.stcChannel, &stc);
printf("decode %.4dx%.4d, pts %#x, stc %#x (diff %d) fifo=%d%%\n",
status.source.width, status.source.height, status.pts, stc, status.ptsStcDifference, status.fifoSize?(status.fifoDepth*100)/status.fifoSize:0);
NEXUS_AudioDecoder_GetStatus(pcmDecoder, &audioStatus);
printf("audio0 pts %#x, stc %#x (diff %d) fifo=%d%%\n",
audioStatus.pts, stc, audioStatus.ptsStcDifference, audioStatus.fifoSize?(audioStatus.fifoDepth*100)/audioStatus.fifoSize:0);
NEXUS_AudioDecoder_GetStatus(compressedDecoder, &audioStatus);
if ( audioStatus.started )
{
printf("audio1 pts %#x, stc %#x (diff %d) fifo=%d%%\n",
audioStatus.pts, stc, audioStatus.ptsStcDifference, audioStatus.fifoSize?(audioStatus.fifoDepth*100)/audioStatus.fifoSize:0);
}
BKNI_Sleep(1000);
}
#else
printf("Press ENTER to stop decode\n");
getchar();
/* example shutdown */
NEXUS_AudioDecoder_Stop(pcmDecoder);
if ( audioProgram.codec == NEXUS_AudioCodec_eAc3 )
{
NEXUS_AudioDecoder_Stop(compressedDecoder);
}
NEXUS_AudioDecoder_Close(pcmDecoder);
NEXUS_AudioDecoder_Close(compressedDecoder);
NEXUS_VideoDecoder_Stop(vdecode);
NEXUS_VideoWindow_Close(window);
NEXUS_Display_Close(display);
NEXUS_VideoDecoder_Close(vdecode);
NEXUS_StcChannel_Close(stcChannel);
NEXUS_PidChannel_Close(videoPidChannel);
NEXUS_PidChannel_Close(audioPidChannel);
NEXUS_Platform_Uninit();
#endif
return 0;
}