66
64
OSVCDec *ctx = (OSVCDec*) ifcg->privateStack;
68
/*not supported in this version*/
69
if (esd->dependsOnESID) return GF_NOT_SUPPORTED;
71
ctx->ES_ID = esd->ESID;
72
ctx->width = ctx->height = ctx->out_size = 0;
66
/*todo: we should check base layer of this stream is indeed our base layer*/
68
ctx->ES_ID = esd->ESID;
69
ctx->width = ctx->height = ctx->out_size = 0;
70
if (!esd->dependsOnESID) ctx->baseES_ID = esd->ESID;
74
73
if (esd->decoderConfig->decoderSpecificInfo && esd->decoderConfig->decoderSpecificInfo->data) {
75
74
GF_AVCConfig *cfg = gf_odf_avc_cfg_read(esd->decoderConfig->decoderSpecificInfo->data, esd->decoderConfig->decoderSpecificInfo->dataLength);
76
75
if (!cfg) return GF_NON_COMPLIANT_BITSTREAM;
77
ctx->nalu_size_length = cfg->nal_unit_size;
78
if (SVCDecoder_init(&ctx->codec) == SVC_STATUS_ERROR) return GF_IO_ERR;
76
if (!esd->dependsOnESID) {
77
ctx->nalu_size_length = cfg->nal_unit_size;
78
if (SVCDecoder_init(&ctx->codec) == SVC_STATUS_ERROR) return GF_IO_ERR;
80
81
/*decode all NALUs*/
81
82
count = gf_list_count(cfg->sequenceParameterSets);
101
102
GF_LOG(GF_LOG_ERROR, GF_LOG_CODEC, ("[SVC Decoder] Error decoding SPS %d\n", res));
104
GF_LOG(GF_LOG_DEBUG, GF_LOG_CODEC, ("[SVC Decoder] Attach: SPS id=\"%d\" code=\"%d\" size=\"%d\"\n", slc->id, slc->data[0] & 0x1F, slc->size));
105
107
count = gf_list_count(cfg->pictureParameterSets);
106
108
for (i=0; i<count; i++) {
107
110
GF_AVCConfigSlot *slc = gf_list_get(cfg->pictureParameterSets, i);
111
gf_avc_get_pps_info(slc->data, slc->size, &pps_id, &sps_id);
108
112
res = decodeNAL(ctx->codec, slc->data, slc->size, &Picture, Layer);
110
114
GF_LOG(GF_LOG_ERROR, GF_LOG_CODEC, ("[SVC Decoder] Error decoding PPS %d\n", res));
116
GF_LOG(GF_LOG_DEBUG, GF_LOG_CODEC, ("[SVC Decoder] Attach: PPS id=\"%d\" code=\"%d\" size=\"%d\" sps_id=\"%d\"\n", pps_id, slc->data[0] & 0x1F, slc->size, sps_id));
118
ctx->state_found = 1;
114
119
gf_odf_avc_cfg_del(cfg);
121
if (ctx->nalu_size_length) {
122
return GF_NOT_SUPPORTED;
116
124
ctx->nalu_size_length = 0;
117
if (SVCDecoder_init(&ctx->codec) == SVC_STATUS_ERROR) return GF_IO_ERR;
125
if (!esd->dependsOnESID) {
126
if (SVCDecoder_init(&ctx->codec) == SVC_STATUS_ERROR) return GF_IO_ERR;
128
ctx->pixel_ar = (1<<16) || 1;
119
130
ctx->stride = ctx->width + 32;
121
ctx->CurrDqId = ctx->layer;
131
ctx->CurrentDqId = ctx->MaxDqId = 0;
122
132
ctx->out_size = ctx->stride * ctx->height * 3 / 2;
184
194
case GF_CODEC_MEDIA_SWITCH_QUALITY:
186
196
if (capability.cap.valueInt) {
187
if (ctx->CurrDqId < ctx->MaxDqId)
197
if (ctx->CurrentDqId < ctx->MaxDqId)
188
198
// set layer up (command=1)
189
UpdateLayer( ctx->DqIdTable, &ctx->CurrDqId, &ctx->TemporalCom, &ctx->TemporalId, ctx->MaxDqId, 1 );
199
UpdateLayer( ctx->DqIdTable, &ctx->CurrentDqId, &ctx->TemporalCom, &ctx->TemporalId, ctx->MaxDqId, 1 );
191
if (ctx->CurrDqId > 0)
201
if (ctx->CurrentDqId > 0)
192
202
// set layer down (command=0)
193
UpdateLayer( ctx->DqIdTable, &ctx->CurrDqId, &ctx->TemporalCom, &ctx->TemporalId, ctx->MaxDqId, 0 );
203
UpdateLayer( ctx->DqIdTable, &ctx->CurrentDqId, &ctx->TemporalCom, &ctx->TemporalId, ctx->MaxDqId, 0 );
224
236
ctx->MaxDqId = GetDqIdMax(inBuffer, inBufferLength, ctx->nalu_size_length, ctx->DqIdTable, ctx->nalu_size_length ? 1 : 0);
225
if(!ctx->InitParseAU){
226
if (ctx->MaxDqId == -1) {
227
//AVC stream in a h264 file
237
if (!ctx->init_layer_set) {
238
//AVC stream in a h264 file
239
if (ctx->MaxDqId == -1)
228
240
ctx->MaxDqId = 0;
230
//Firts time only, we parse the first AU to know the file configuration
231
//does not need to ba called again ever after, unless SPS or PPS changed
232
ParseAuPlayers(ctx->codec, inBuffer, inBufferLength, ctx->nalu_size_length, ctx->nalu_size_length ? 1 : 0);
234
ctx->InitParseAU = 1;
242
ctx->CurrentDqId = ctx->MaxDqId;
243
ctx->init_layer_set = 1;
237
245
if (curMaxDqId != ctx->MaxDqId)
239
if (ctx->MaxDqId == -1)
242
ParseAuPlayers(ctx->codec, inBuffer, inBufferLength, ctx->nalu_size_length, ctx->nalu_size_length ? 1 : 0);
243
ctx->CurrDqId = ctx->MaxDqId;
245
// SetCommandLayer(Layer, ctx->MaxDqId, ctx->CurrDqId, &ctx->TemporalCom, ctx->TemporalId);
247
ctx->TemporalCom = 0;
248
SetCommandLayer(Layer, ctx->MaxDqId, ctx->MaxDqId, &ctx->TemporalCom, 0);
246
ctx->CurrentDqId = ctx->MaxDqId;
247
/*decode only current layer*/
248
SetCommandLayer(Layer, ctx->MaxDqId, ctx->CurrentDqId, &ctx->TemporalCom, ctx->TemporalId);
251
if (ctx->nalu_size_length) {
252
u32 i, nalu_size = 0;
255
while (inBufferLength) {
254
if (!ctx->nalu_size_length) {
257
size = gf_media_nalu_next_start_code(inBuffer, inBufferLength, &sc_size);
260
assert(inBufferLength >= size+sc_size);
261
inBufferLength -= size+sc_size;
263
/*no annex-B start-code found, discard */
264
*outBufferLength = 0;
269
while (inBufferLength) {
270
if (ctx->nalu_size_length) {
256
271
for (i=0; i<ctx->nalu_size_length; i++) {
257
272
nalu_size = (nalu_size<<8) + ptr[i];
259
274
ptr += ctx->nalu_size_length;
277
nalu_size = gf_media_nalu_next_start_code(ptr, inBufferLength, &sc_size);
279
#ifndef GPAC_DISABLE_LOG
280
switch (ptr[0] & 0x1F) {
281
case GF_AVC_NALU_SEQ_PARAM:
282
case GF_AVC_NALU_SVC_SUBSEQ_PARAM:
285
gf_avc_get_sps_info((char *)ptr, nalu_size, &sps_id, NULL, NULL, NULL, NULL);
286
GF_LOG(GF_LOG_DEBUG, GF_LOG_CODEC, ("[SVC Decoder] ES%d: SPS id=\"%d\" code=\"%d\" size=\"%d\"\n", ES_ID, sps_id, ptr[0] & 0x1F, nalu_size));
289
case GF_AVC_NALU_PIC_PARAM:
292
gf_avc_get_pps_info((char *)ptr, nalu_size, &pps_id, &sps_id);
293
GF_LOG(GF_LOG_DEBUG, GF_LOG_CODEC, ("[SVC Decoder] ES%d: PPS id=\"%d\" code=\"%d\" size=\"%d\" sps_id=\"%d\"\n", ES_ID, pps_id, ptr[0] & 0x1F, nalu_size, sps_id));
297
GF_LOG(GF_LOG_DEBUG, GF_LOG_CODEC, ("[SVC Decoder] ES%d: NALU code=\"%d\" size=\"%d\"\n", ES_ID, ptr[0] & 0x1F, nalu_size));
300
if (!ctx->state_found) {
301
u8 nal_type = (ptr[0] & 0x1F) ;
303
case GF_AVC_NALU_SEQ_PARAM:
304
case GF_AVC_NALU_PIC_PARAM:
305
if (ctx->baseES_ID == ES_ID)
306
ctx->state_found = 1;
311
if (ctx->state_found) {
262
313
got_pic = decodeNAL(ctx->codec, ptr, nalu_size, &pic, Layer);
264
315
decodeNAL(ctx->codec, ptr, nalu_size, &pic, Layer);
319
if (ctx->nalu_size_length) {
267
320
if (inBufferLength < nalu_size + ctx->nalu_size_length) break;
269
321
inBufferLength -= nalu_size + ctx->nalu_size_length;
323
if (!sc_size || (inBufferLength < nalu_size + sc_size)) break;
324
inBufferLength -= nalu_size + sc_size;
273
if (got_pic!=1) return GF_OK;
330
*outBufferLength = 0;
275
334
if ((curMaxDqId != ctx->MaxDqId) || (pic.Width != ctx->width) || (pic.Height!=ctx->height)) {
335
GF_LOG(GF_LOG_INFO, GF_LOG_CODEC, ("[SVC Decoder] Resizing from %dx%d to %dx%d\n", ctx->width, ctx->height, pic.Width, pic.Height ));
276
336
ctx->width = pic.Width;
277
337
ctx->stride = pic.Width + 32;
278
338
ctx->height = pic.Height;
279
339
ctx->out_size = ctx->stride * ctx->height * 3 / 2;
281
340
/*always force layer resize*/
282
341
*outBufferLength = ctx->out_size;
283
342
return GF_BUFFER_TOO_SMALL;