<commit_before>/*****************************************************************************
 * vc1.c
 *****************************************************************************
 * Copyright (C) 2001, 2002, 2006 the VideoLAN team
 * $Id$
 *
 * Authors: <NAME> <<EMAIL>>
 *          <NAME> <<EMAIL>>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
 *****************************************************************************/

/*****************************************************************************
 * Preamble
 *****************************************************************************/

#ifdef HAVE_CONFIG_H
# include "config.h"
#endif

#include <vlc_common.h>
#include <vlc_plugin.h>
#include <vlc_codec.h>
#include <vlc_block.h>

#include "vlc_bits.h"
#include "vlc_block_helper.h"

/*****************************************************************************
 * Module descriptor
 *****************************************************************************/
static int  Open ( vlc_object_t * );
static void Close( vlc_object_t * );

vlc_module_begin ()
    set_category( CAT_SOUT )
    set_subcategory( SUBCAT_SOUT_PACKETIZER )
    set_description( N_("VC-1 packetizer") )
    set_capability( "packetizer", 50 )
    set_callbacks( Open, Close )
vlc_module_end ()

/*****************************************************************************
 * Local prototypes
 *****************************************************************************/
struct decoder_sys_t
{
    /*
     * Input properties
     */
    block_bytestream_t bytestream;
    int i_state;
    size_t i_offset;
    uint8_t p_startcode[3];

    /* Current sequence header */
    bool b_sequence_header;
    struct
    {
        block_t *p_sh;
        bool b_advanced_profile;
        bool b_interlaced;
        bool b_frame_interpolation;
        bool b_range_reduction;
        bool b_has_bframe;
    } sh;
    bool b_entry_point;
    struct
    {
        block_t *p_ep;
    } ep;

    /* */
    bool  b_frame;

    /* Current frame being built */
    block_t    *p_frame;
    block_t    **pp_last;


    mtime_t i_interpolated_dts;
};

enum
{
    STATE_NOSYNC,
    STATE_NEXT_SYNC
};

typedef enum
{
    IDU_TYPE_SEQUENCE_HEADER = 0x0f,
    IDU_TYPE_ENTRY_POINT = 0x0e,
    IDU_TYPE_FRAME = 0x0D,
    IDU_TYPE_FIELD = 0x0C,
    IDU_TYPE_SLICE = 0x0B,
    IDU_TYPE_END_OF_SEQUENCE = 0x0A,

    IDU_TYPE_SEQUENCE_LEVEL_USER_DATA = 0x1F,
    IDU_TYPE_ENTRY_POINT_USER_DATA = 0x1E,
    IDU_TYPE_FRAME_USER_DATA = 0x1D,
    IDU_TYPE_FIELD_USER_DATA = 0x1C,
    IDU_TYPE_SLICE_USER_DATA = 0x1B,
} idu_type_t;

static block_t *Packetize( decoder_t *p_dec, block_t **pp_block );

/*****************************************************************************
 * Open: probe the packetizer and return score
 *****************************************************************************
 * Tries to launch a decoder and return score so that the interface is able
 * to choose.
 *****************************************************************************/
static int Open( vlc_object_t *p_this )
{
    decoder_t     *p_dec = (decoder_t*)p_this;
    decoder_sys_t *p_sys;

    if( p_dec->fmt_in.i_codec !=  VLC_FOURCC( 'W', 'V', 'C', '1' ) )
        return VLC_EGENERIC;

    p_dec->pf_packetize = Packetize;

    /* Create the output format */
    es_format_Copy( &p_dec->fmt_out, &p_dec->fmt_in );
    p_dec->p_sys = p_sys = malloc( sizeof( decoder_sys_t ) );

    p_sys->i_state = STATE_NOSYNC;
    p_sys->bytestream = block_BytestreamInit();
    p_sys->p_startcode[0] = 0x00;
    p_sys->p_startcode[1] = 0x00;
    p_sys->p_startcode[2] = 0x01;
    p_sys->i_offset = 0;

    p_sys->b_sequence_header = false;
    p_sys->sh.p_sh = NULL;
    p_sys->b_entry_point = false;
    p_sys->ep.p_ep = NULL;

    p_sys->b_frame = false;
    p_sys->p_frame = NULL;
    p_sys->pp_last = &p_sys->p_frame;

    p_sys->i_interpolated_dts = -1;


    if( p_dec->fmt_in.i_extra > 0 )
    {
        block_t *p_init = block_New( p_dec, p_dec->fmt_in.i_extra );
        block_t *p_pic;

        memcpy( p_init->p_buffer, p_dec->fmt_in.p_extra,
                p_dec->fmt_in.i_extra );

        while( ( p_pic = Packetize( p_dec, &p_init ) ) )
            block_Release( p_pic ); /* Should not happen (only sequence header) */
    }

    return VLC_SUCCESS;<commit_msg>Fixed extra data parsing with some VC1 streams.<commit_after>/*****************************************************************************
 * vc1.c
 *****************************************************************************
 * Copyright (C) 2001, 2002, 2006 the VideoLAN team
 * $Id$
 *
 * Authors: <NAME> <<EMAIL>>
 *          <NAME> <<EMAIL>>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
 *****************************************************************************/

/*****************************************************************************
 * Preamble
 *****************************************************************************/

#ifdef HAVE_CONFIG_H
# include "config.h"
#endif

#include <vlc_common.h>
#include <vlc_plugin.h>
#include <vlc_codec.h>
#include <vlc_block.h>

#include "vlc_bits.h"
#include "vlc_block_helper.h"

/*****************************************************************************
 * Module descriptor
 *****************************************************************************/
static int  Open ( vlc_object_t * );
static void Close( vlc_object_t * );

vlc_module_begin ()
    set_category( CAT_SOUT )
    set_subcategory( SUBCAT_SOUT_PACKETIZER )
    set_description( N_("VC-1 packetizer") )
    set_capability( "packetizer", 50 )
    set_callbacks( Open, Close )
vlc_module_end ()

/*****************************************************************************
 * Local prototypes
 *****************************************************************************/
struct decoder_sys_t
{
    /*
     * Input properties
     */
    block_bytestream_t bytestream;
    int i_state;
    size_t i_offset;
    uint8_t p_startcode[3];

    /* Current sequence header */
    bool b_sequence_header;
    struct
    {
        block_t *p_sh;
        bool b_advanced_profile;
        bool b_interlaced;
        bool b_frame_interpolation;
        bool b_range_reduction;
        bool b_has_bframe;
    } sh;
    bool b_entry_point;
    struct
    {
        block_t *p_ep;
    } ep;

    /* */
    bool  b_frame;

    /* Current frame being built */
    block_t    *p_frame;
    block_t    **pp_last;


    mtime_t i_interpolated_dts;
};

enum
{
    STATE_NOSYNC,
    STATE_NEXT_SYNC
};

typedef enum
{
    IDU_TYPE_SEQUENCE_HEADER = 0x0f,
    IDU_TYPE_ENTRY_POINT = 0x0e,
    IDU_TYPE_FRAME = 0x0D,
    IDU_TYPE_FIELD = 0x0C,
    IDU_TYPE_SLICE = 0x0B,
    IDU_TYPE_END_OF_SEQUENCE = 0x0A,

    IDU_TYPE_SEQUENCE_LEVEL_USER_DATA = 0x1F,
    IDU_TYPE_ENTRY_POINT_USER_DATA = 0x1E,
    IDU_TYPE_FRAME_USER_DATA = 0x1D,
    IDU_TYPE_FIELD_USER_DATA = 0x1C,
    IDU_TYPE_SLICE_USER_DATA = 0x1B,
} idu_type_t;

static block_t *Packetize( decoder_t *p_dec, block_t **pp_block );

/*****************************************************************************
 * Open: probe the packetizer and return score
 *****************************************************************************
 * Tries to launch a decoder and return score so that the interface is able
 * to choose.
 *****************************************************************************/
static int Open( vlc_object_t *p_this )
{
    decoder_t     *p_dec = (decoder_t*)p_this;
    decoder_sys_t *p_sys;

    if( p_dec->fmt_in.i_codec !=  VLC_FOURCC( 'W', 'V', 'C', '1' ) )
        return VLC_EGENERIC;

    p_dec->pf_packetize = Packetize;

    /* Create the output format */
    es_format_Copy( &p_dec->fmt_out, &p_dec->fmt_in );
    p_dec->p_sys = p_sys = malloc( sizeof( decoder_sys_t ) );

    p_sys->i_state = STATE_NOSYNC;
    p_sys->bytestream = block_BytestreamInit();
    p_sys->p_startcode[0] = 0x00;
    p_sys->p_startcode[1] = 0x00;
    p_sys->p_startcode[2] = 0x01;
    p_sys->i_offset = 0;

    p_sys->b_sequence_header = false;
    p_sys->sh.p_sh = NULL;
    p_sys->b_entry_point = false;
    p_sys->ep.p_ep = NULL;

    p_sys->b_frame = false;
    p_sys->p_frame = NULL;
    p_sys->pp_last = &p_sys->p_frame;

    p_sys->i_interpolated_dts = -1;

    /* */
    if( p_dec->fmt_out.i_extra > 0 )
    {
        uint8_t *p_extra = p_dec->fmt_out.p_extra;

        /* With (some) ASF the first byte has to be stripped */
        if( p_extra[0] != 0x00 )
        {
            memcpy( &p_extra[0], &p_extra[1], p_dec->fmt_out.i_extra - 1 );
            p_dec->fmt_out.i_extra--;
        }

        /* */
        if( p_dec->fmt_out.i_extra > 0 )
        {
            block_t *p_init = block_New( p_dec, p_dec->fmt_out.i_extra );

            memcpy( p_init->p_buffer, p_dec->fmt_out.p_extra,
                    p_dec->fmt_out.i_extra );

            block_t *p_pic;
            while( ( p_pic = Packetize( p_dec, &p_init ) ) )
                block_Release( p_pic ); /* Should not happen (only sequence header) */
        }
    }

    return VLC_SUCCESS;
{'fraction_non_alphanumeric': 0.26135274956888294, 'fraction_numerical': 0.013987353899214409, 'mean_word_length': 3.6047640052933394, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 80, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4478228', 'n_tokens_mistral': 3524, 'n_tokens_neox': 3260, 'n_words': 773}