Beispiel #1
0
/*!
 * \param *media: A pointer to a MediaFile_t structure, containing every informations available about the current media file.
 * \param tid: Track ID.
 * \return A pointer to the newlee allocated DecodingContext.
 *
 * Initialize the DecodingContext and it's bitstream (with a MediaFile_t passed in parameters),
 * then NAL Unit structure, then init all pointer's (sps, pps, sei) to NULL.
 */
DecodingContext_t *initDecodingContext(MediaFile_t *media, unsigned tid)
{
    TRACE_INFO(H264, BLD_GREEN "initDecodingContext()" CLR_RESET);
    DecodingContext_t *dc = NULL;

    if (media != NULL &&
        tid < media->tracks_video_count &&
        media->tracks_video[tid] != NULL)
    {
        // DecodingContext allocation
        dc = (DecodingContext_t*)calloc(1, sizeof(DecodingContext_t));

        if (dc == NULL)
        {
            TRACE_ERROR(H264, "Unable to alloc new DecodingContext!");
        }
        else
        {
            // Select media and track
            dc->MediaFile = media;
            dc->VideoStream = media->tracks_video[tid];
            dc->active_tid = tid;

            // Init some quantization parameters
            computeNormAdjust(dc);

            // Init input bitstream
            dc->bitstr = init_bitstream(media, media->tracks_video[tid]);

            if (dc->bitstr == NULL)
            {
                free(dc);
                dc = NULL;
            }
            else
            {
                // Init NAL Unit
                dc->active_nalu = initNALU();

                if (dc->active_nalu == NULL)
                {
                    free(dc->bitstr);
                    dc->bitstr = NULL;

                    free(dc);
                    dc = NULL;
                }
            }
        }
    }

    // Return the DecodingContext
    return dc;
}
Beispiel #2
0
/*!
 * \brief Free decoding context.
 * \param *video A pointer to a VideoFile_t structure, containing every informations available about the current video file.
 * \return A pointer to the newlee allocated DecodingContext.
 *
 * Initialize the DecodingContext and it's bitstream (with a VideoFile_t passed in parameters),
 * then NAL Unit structure, then init all pointer's (sps, pps, sei) to NULL.
 */
DecodingContext_t *initDecodingContext(VideoFile_t *video)
{
    TRACE_INFO(H264, BLD_GREEN "initDecodingContext()\n" CLR_RESET);
    DecodingContext_t *dc = NULL;

    if (video != NULL)
    {
        // DecodingContext allocation
        dc = (DecodingContext_t*)calloc(1, sizeof(DecodingContext_t));

        if (dc == NULL)
        {
            TRACE_ERROR(H264, "Unable to alloc new DecodingContext!\n");
        }
        else
        {
            // Init output variables
            dc->output_format = 0;
            dc->picture_quality = 75;
            dc->picture_number = 1;
            dc->picture_extractionmode = 0;

            // Init input bitstream
            dc->VideoFile = video;
            dc->bitstr = init_bitstream(video, video->tracks_video[0]);

            if (dc->bitstr == NULL)
            {
                free(dc);
                dc = NULL;
            }
            else
            {
                // Init NAL Unit
                dc->active_nalu = initNALU();

                if (dc->active_nalu == NULL)
                {
                    free(dc->bitstr);
                    dc->bitstr = NULL;

                    free(dc);
                    dc = NULL;
                }
                else
                {
                    // Cleanup array of SPS and PPS
                    int i = 0;

                    for (i = 0; i < MAX_SPS; i++)
                    {
                        dc->sps_array[i] = NULL;
                    }

                    for (i = 0; i < MAX_PPS; i++)
                    {
                        dc->pps_array[i] = NULL;
                    }

                    dc->active_sei = NULL;

                    dc->active_slice = NULL;

                    dc->mb_array = NULL;

                    TRACE_1(H264, "* DecodingContext allocation success\n");
                }
            }
        }
    }

    // Return the DecodingContext
    return dc;
}