~ubuntu-branches/debian/experimental/gpac/experimental

« back to all changes in this revision

Viewing changes to modules/opensvc_dec/opensvc_dec.c

  • Committer: Package Import Robot
  • Author(s): Reinhard Tartler
  • Date: 2014-02-22 18:15:00 UTC
  • mfrom: (1.2.2) (3.1.6 sid)
  • Revision ID: package-import@ubuntu.com-20140222181500-b4phupo05gjpmopa
Tags: 0.5.0+svn5104~dfsg1-1
* New  upstream version 0.5.0+svn5104~dfsg1:
  - src/utils/sha1.c is relicensed under LGPLv2.1, Closes: #730759
* Don't install modules in multi-arch directories, Closes: #730497
* Add libusb-1.0.0-dev headers because libfreenect requires this
* Fix install rule
* Follow upstream soname bump
  - Drop the symbols file for now until it has been revised thourougly
* Let binaries produce the correct svn revision
* Refresh patches
* Patch and build against libav10, Closes: #739321
* Bump standards version, no changes necessary

Show diffs side-by-side

added added

removed removed

Lines of Context:
27
27
#include <gpac/modules/codec.h>
28
28
#include <gpac/avparse.h>
29
29
#include <gpac/constants.h>
 
30
#include <gpac/internal/media_dev.h>
30
31
 
31
32
 
32
33
#if (defined(WIN32) || defined(_WIN32_WCE)) && !defined(__GNUC__)
34
35
#endif
35
36
 
36
37
#include <OpenSVCDecoder/SVCDecoder_ietr_api.h>
37
 
#include <OpenSVCDecoder/ParseAU.h>
38
38
 
39
39
typedef struct
40
40
{
41
41
        u16 ES_ID;
42
 
        u32 width, stride, height, out_size, pixel_ar, layer;
43
 
        Bool first_frame;
 
42
        u16 baseES_ID;
 
43
        u32 width, stride, height, out_size, pixel_ar;
44
44
 
45
45
        u32 nalu_size_length;
 
46
        Bool init_layer_set;
 
47
        Bool state_found;
46
48
 
47
49
        /*OpenSVC things*/
48
50
        void *codec;
49
 
        int InitParseAU;
50
 
        int svc_init_done;
51
 
        int save_Width;
52
 
        int save_Height;
53
 
        int CurrDqId;
 
51
        int CurrentDqId;
54
52
        int MaxDqId;
55
 
        int DqIdTable [8];
 
53
        int DqIdTable[8];
56
54
    int TemporalId;
57
55
    int TemporalCom;
58
56
} OSVCDec;
65
63
        int Layer[4];
66
64
        OSVCDec *ctx = (OSVCDec*) ifcg->privateStack;
67
65
 
68
 
        /*not supported in this version*/
69
 
        if (esd->dependsOnESID) return GF_NOT_SUPPORTED;
70
 
        
71
 
        ctx->ES_ID = esd->ESID;
72
 
        ctx->width = ctx->height = ctx->out_size = 0;
73
 
        
 
66
        /*todo: we should check base layer of this stream is indeed our base layer*/    
 
67
        if (!ctx->ES_ID) {
 
68
                ctx->ES_ID = esd->ESID;
 
69
                ctx->width = ctx->height = ctx->out_size = 0;
 
70
                if (!esd->dependsOnESID) ctx->baseES_ID = esd->ESID;
 
71
        }
 
72
 
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;
 
79
                }
79
80
 
80
81
                /*decode all NALUs*/
81
82
                count = gf_list_count(cfg->sequenceParameterSets);
100
101
                        if (res<0) {
101
102
                                GF_LOG(GF_LOG_ERROR, GF_LOG_CODEC, ("[SVC Decoder] Error decoding SPS %d\n", res));
102
103
                        }
 
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));
103
105
                }
104
106
 
105
107
                count = gf_list_count(cfg->pictureParameterSets);
106
108
                for (i=0; i<count; i++) {
 
109
                        u32 sps_id, pps_id;
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);
109
113
                        if (res<0) {
110
114
                                GF_LOG(GF_LOG_ERROR, GF_LOG_CODEC, ("[SVC Decoder] Error decoding PPS %d\n", res));
111
115
                        }
 
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));
112
117
                }
113
 
 
 
118
                ctx->state_found = 1;
114
119
                gf_odf_avc_cfg_del(cfg);
115
120
        } else {
 
121
                if (ctx->nalu_size_length) {
 
122
                        return GF_NOT_SUPPORTED;
 
123
                }
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;
 
127
                }
 
128
                ctx->pixel_ar = (1<<16) || 1;
118
129
        }
119
130
        ctx->stride = ctx->width + 32;
120
 
        ctx->layer = 0;
121
 
        ctx->CurrDqId = ctx->layer;
 
131
        ctx->CurrentDqId = ctx->MaxDqId = 0;
122
132
        ctx->out_size = ctx->stride * ctx->height * 3 / 2;
123
133
        return GF_OK;
124
134
}
184
194
        case GF_CODEC_MEDIA_SWITCH_QUALITY:
185
195
 
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 );
190
200
                } else {
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 );
194
204
                }
195
205
                return GF_OK;
196
206
        }
209
219
        s32 got_pic;
210
220
        OPENSVCFRAME pic;
211
221
    int Layer[4];
 
222
        u32 i, nalu_size, sc_size;
 
223
        u8 *ptr;
212
224
        OSVCDec *ctx = (OSVCDec*) ifcg->privateStack;
213
225
        u32 curMaxDqId = ctx->MaxDqId;
214
226
 
215
 
        if (!ES_ID || (ES_ID!=ctx->ES_ID) || !ctx->codec) {
 
227
        if (!ES_ID || !ctx->codec) {
216
228
                *outBufferLength = 0;
217
229
                return GF_OK;
218
230
        }
222
234
        }
223
235
 
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;
229
 
                } else {
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);
233
 
                }
234
 
                ctx->InitParseAU = 1;
 
241
                
 
242
                ctx->CurrentDqId = ctx->MaxDqId;
 
243
                ctx->init_layer_set = 1;
235
244
        }
236
 
/*
237
245
        if (curMaxDqId != ctx->MaxDqId)
238
 
        {
239
 
                if (ctx->MaxDqId == -1)
240
 
                        ctx->MaxDqId = 0;
241
 
                else
242
 
                        ParseAuPlayers(ctx->codec, inBuffer, inBufferLength, ctx->nalu_size_length, ctx->nalu_size_length ? 1 : 0);
243
 
                ctx->CurrDqId = ctx->MaxDqId;
244
 
        }
245
 
//      SetCommandLayer(Layer, ctx->MaxDqId, ctx->CurrDqId, &ctx->TemporalCom, ctx->TemporalId);
246
 
*/
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);
249
249
 
250
250
        got_pic = 0;
251
 
        if (ctx->nalu_size_length) {
252
 
                u32 i, nalu_size = 0;
253
 
                u8 *ptr = inBuffer;
254
 
 
255
 
                while (inBufferLength) {
 
251
        nalu_size = 0;
 
252
        ptr = inBuffer;
 
253
 
 
254
        if (!ctx->nalu_size_length) {
 
255
                u32 size;
 
256
                sc_size = 0;
 
257
                size = gf_media_nalu_next_start_code(inBuffer, inBufferLength, &sc_size);
 
258
                if (sc_size) {
 
259
                        ptr += size+sc_size;
 
260
                        assert(inBufferLength >= size+sc_size);
 
261
                        inBufferLength -= size+sc_size;
 
262
                } else {
 
263
                        /*no annex-B start-code found, discard */
 
264
                        *outBufferLength = 0;
 
265
                        return GF_OK;
 
266
                }
 
267
        }
 
268
 
 
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];
258
273
                        }
259
274
                        ptr += ctx->nalu_size_length;
 
275
                } else {
 
276
                        u32 sc_size;
 
277
                        nalu_size = gf_media_nalu_next_start_code(ptr, inBufferLength, &sc_size);
 
278
                }
 
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:
 
283
                                {
 
284
                                        u32 sps_id;
 
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));
 
287
                                }
 
288
                                break;
 
289
                        case GF_AVC_NALU_PIC_PARAM:
 
290
                                {
 
291
                                        u32 sps_id, pps_id;
 
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));
 
294
                                }
 
295
                                break;
 
296
                        default:
 
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));
 
298
                }
 
299
#endif
 
300
                if (!ctx->state_found) {
 
301
                        u8 nal_type = (ptr[0] & 0x1F) ;
 
302
                        switch (nal_type) {
 
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;
 
307
                                break;
 
308
                        }
 
309
                }
260
310
 
 
311
                if (ctx->state_found) {
261
312
                        if (!got_pic) 
262
313
                                got_pic = decodeNAL(ctx->codec, ptr, nalu_size, &pic, Layer);
263
314
                        else
264
315
                                decodeNAL(ctx->codec, ptr, nalu_size, &pic, Layer);
 
316
                }
265
317
 
266
 
                        ptr += nalu_size;
 
318
                ptr += nalu_size;
 
319
                if (ctx->nalu_size_length) {
267
320
                        if (inBufferLength < nalu_size + ctx->nalu_size_length) break;
268
 
 
269
321
                        inBufferLength -= nalu_size + ctx->nalu_size_length;
 
322
                } else {
 
323
                        if (!sc_size || (inBufferLength < nalu_size + sc_size)) break;
 
324
                        inBufferLength -= nalu_size + sc_size;
 
325
                        ptr += sc_size;
270
326
                }
271
 
        } else {
272
 
        }
273
 
        if (got_pic!=1) return GF_OK;
 
327
        }
 
328
 
 
329
        if (got_pic!=1) {
 
330
                *outBufferLength = 0;
 
331
                return GF_OK;
 
332
        }
274
333
 
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;
280
 
 
281
340
                /*always force layer resize*/
282
341
                *outBufferLength = ctx->out_size;
283
342
                return GF_BUFFER_TOO_SMALL;
299
358
 
300
359
        switch (esd->decoderConfig->objectTypeIndication) {
301
360
        case GPAC_OTI_VIDEO_AVC:
 
361
        case GPAC_OTI_VIDEO_SVC:
302
362
                if (esd->decoderConfig->decoderSpecificInfo && esd->decoderConfig->decoderSpecificInfo->data) {
303
363
                        Bool is_svc = 0;
304
364
                        u32 i, count;
322
382
                        gf_odf_avc_cfg_del(cfg);
323
383
                        return is_svc ? GF_CODEC_SUPPORTED : GF_CODEC_MAYBE_SUPPORTED;
324
384
                }
325
 
                return GF_CODEC_MAYBE_SUPPORTED;
 
385
                return esd->has_ref_base ? GF_CODEC_SUPPORTED : GF_CODEC_MAYBE_SUPPORTED;
326
386
        }
327
387
        return GF_CODEC_NOT_SUPPORTED;
328
388
}
361
421
        gf_free(ifcg);
362
422
}
363
423
 
364
 
GF_EXPORT
 
424
GPAC_MODULE_EXPORT
365
425
const u32 *QueryInterfaces() 
366
426
{
367
427
        static u32 si [] = {
373
433
        return si; 
374
434
}
375
435
 
376
 
GF_EXPORT
 
436
GPAC_MODULE_EXPORT
377
437
GF_BaseInterface *LoadInterface(u32 InterfaceType) 
378
438
{
379
439
#ifndef GPAC_DISABLE_AV_PARSERS
382
442
        return NULL;
383
443
}
384
444
 
385
 
GF_EXPORT
 
445
GPAC_MODULE_EXPORT
386
446
void ShutdownInterface(GF_BaseInterface *ifce)
387
447
{
388
448
        switch (ifce->InterfaceType) {
393
453
#endif
394
454
        }
395
455
}
 
456
 
 
457
GPAC_MODULE_STATIC_DELARATION( opensvc )
 
458