Ticket #9410: fix9410-bbc-hd.patch

File fix9410-bbc-hd.patch, 8.4 KB (added by mythtv@…, 9 years ago)

Patch refered to from Comment 5. Includes previous patch

  • mythtv/libs/libmythtv/mpeg/H264Parser.cpp

    diff --git a/mythtv/libs/libmythtv/mpeg/H264Parser.cpp b/mythtv/libs/libmythtv/mpeg/H264Parser.cpp
    old mode 100644
    new mode 100755
    index ac805e7..cabdfc5
    a b static const float eps = 1E-5; 
    9292
    9393H264Parser::H264Parser(void)
    9494{
     95    rbsp_buffer      = NULL;
     96    rbsp_buffer_size = 0;
    9597    Reset();
    9698    I_is_keyframe = true;
    9799    memset(&gb, 0, sizeof(gb));
    bool H264Parser::new_AU(void) 
    183185      one or more of the following ways.
    184186
    185187      - frame_num differs in value. The value of frame_num used to
    186       test this condition is the value of frame_num that appears in
    187       the syntax of the slice header, regardless of whether that value
    188       is inferred to have been equal to 0 for subsequent use in the
    189       decoding process due to the presence of
    190       memory_management_control_operation equal to 5.
     188        test this condition is the value of frame_num that appears in
     189        the syntax of the slice header, regardless of whether that value
     190        is inferred to have been equal to 0 for subsequent use in the
     191        decoding process due to the presence of
     192        memory_management_control_operation equal to 5.
    191193          Note: If the current picture is an IDR picture FrameNum and
    192194          PrevRefFrameNum are set equal to 0.
    193195      - pic_parameter_set_id differs in value.
    194196      - field_pic_flag differs in value.
    195197      - bottom_field_flag is present in both and differs in value.
    196       - nal_ref_idc differs in value with one of the nal_ref_idc values
    197       being equal to 0.
     198      - nal_ref_idc differs in value with one of the nal_ref_idc
     199        values being equal to 0.
    198200      - pic_order_cnt_type is equal to 0 for both and either
    199       pic_order_cnt_lsb differs in value, or delta_pic_order_cnt_bottom
    200       differs in value.
     201        pic_order_cnt_lsb differs in value, or delta_pic_order_cnt_bottom
     202        differs in value.
    201203      - pic_order_cnt_type is equal to 1 for both and either
    202       delta_pic_order_cnt[0] differs in value, or
    203       delta_pic_order_cnt[1] differs in value.
     204        delta_pic_order_cnt[0] differs in value, or
     205        delta_pic_order_cnt[1] differs in value.
    204206      - nal_unit_type differs in value with one of the nal_unit_type values
    205       being equal to 5.
     207        being equal to 5.
    206208      - nal_unit_type is equal to 5 for both and idr_pic_id differs in
    207       value.
     209        value.
    208210
    209211      NOTE – Some of the VCL NAL units in redundant coded pictures or some
    210212      non-VCL NAL units (e.g. an access unit delimiter NAL unit) may also
    bool H264Parser::new_AU(void) 
    230232        else if ((bottom_field_flag != -1 && prev_bottom_field_flag != -1) &&
    231233                 bottom_field_flag != prev_bottom_field_flag)
    232234            result = true;
     235        else if ((nal_ref_idc == 0 || prev_nal_ref_idc == 0) &&
     236                 nal_ref_idc != prev_nal_ref_idc)
     237            result = true;
    233238        else if ((pic_order_cnt_type == 0 && prev_pic_order_cnt_type == 0) &&
    234239                 (pic_order_cnt_lsb != prev_pic_order_cnt_lsb ||
    235240                  delta_pic_order_cnt_bottom !=
    bool H264Parser::new_AU(void) 
    253258    prev_pic_parameter_set_id = pic_parameter_set_id;
    254259    prev_field_pic_flag = field_pic_flag;
    255260    prev_bottom_field_flag = bottom_field_flag;
     261    prev_nal_ref_idc = nal_ref_idc;
    256262    prev_pic_order_cnt_lsb = pic_order_cnt_lsb;
    257263    prev_delta_pic_order_cnt_bottom = delta_pic_order_cnt_bottom;
    258264    prev_delta_pic_order_cnt[0] = delta_pic_order_cnt[0];
    bool H264Parser::new_AU(void) 
    263269    return result;
    264270}
    265271
     272uint32_t H264Parser::load_rbsp(const uint8_t *byteP, uint32_t byte_count)
     273{
     274    uint32_t rbsp_index        = 0;
     275    uint32_t consecutive_zeros = 0;
     276
     277    if(rbsp_buffer_size < byte_count)
     278    {
     279        delete [] rbsp_buffer;
     280        rbsp_buffer_size = 0;
     281
     282        rbsp_buffer = new uint8_t[byte_count];
     283        if(rbsp_buffer == NULL)
     284            return 0;
     285
     286        rbsp_buffer_size = byte_count;
     287    }
     288
     289    /* From rbsp while we have data and we don't run into a
     290     * new start code */
     291    while(byte_count && (consecutive_zeros < 2 || *byteP != 0x01))
     292    {
     293        /* Copy the byte into the rbsp, unless it
     294         * is the 0x03 in a 0x000003 */
     295        if(consecutive_zeros < 2 || *byteP != 0x03)
     296            rbsp_buffer[rbsp_index++] = *byteP;
     297
     298        if(*byteP == 0)
     299            consecutive_zeros += 1;
     300        else
     301            consecutive_zeros = 0;
     302
     303        byteP += 1;
     304        byte_count -= 1;
     305    }
     306
     307    return rbsp_index;
     308}
     309
    266310uint32_t H264Parser::addBytes(const uint8_t  *bytes,
    267311                              const uint32_t  byte_count,
    268312                              const uint64_t  stream_offset)
    uint32_t H264Parser::addBytes(const uint8_t *bytes, 
    306350            if (nal_unit_type == SPS || nal_unit_type == PPS ||
    307351                nal_unit_type == SEI || NALisSlice(nal_unit_type))
    308352            {
     353                uint32_t rbsp_size;
     354
     355                rbsp_size = load_rbsp(byteP, endP - byteP);
     356
    309357                /*
    310358                  bitstream buffer, must be FF_INPUT_BUFFER_PADDING_SIZE
    311359                  bytes larger then the actual read bits
    312360                */
    313                 if (byteP + 1 + FF_INPUT_BUFFER_PADDING_SIZE < endP)
     361                if (FF_INPUT_BUFFER_PADDING_SIZE <= rbsp_size)
    314362                {
    315                     init_get_bits(&gb, byteP, 8 * (endP - byteP));
     363                    init_get_bits(&gb, rbsp_buffer, 8 * rbsp_size);
    316364
    317365                    if (nal_unit_type == SEI)
    318366                    {
    uint32_t H264Parser::addBytes(const uint8_t *bytes, 
    335383                        if (new_AU())
    336384                            set_AU_pending(stream_offset);
    337385                    }
    338 
    339                     byteP += (get_bits_count(&gb) / 8);
    340386                }
    341387            }
    342388            else if (!AU_pending)
    uint32_t H264Parser::addBytes(const uint8_t *bytes, 
    348394                    AU_pending = true;
    349395                    AU_offset = stream_offset;
    350396                }
    351                 else if ((nal_ref_idc == 0 || prev_nal_ref_idc == 0) &&
    352                          nal_ref_idc != prev_nal_ref_idc)
    353                 {
    354                     AU_pending = true;
    355                     AU_offset = stream_offset;
    356                 }
    357397            }
    358398
    359399            if (AU_pending && NALisSlice(nal_unit_type))
    uint32_t H264Parser::addBytes(const uint8_t *bytes, 
    378418            else
    379419                on_frame = on_key_frame = false;
    380420
    381             prev_nal_ref_idc = nal_ref_idc;
    382 
    383421            return byteP - bytes;
    384422        }
    385423    }
    void H264Parser::decode_SPS(GetBitContext * gb) 
    600638        {
    601639            for (int idx = 0; idx < ((chroma_format_idc != 3) ? 8 : 12); ++idx)
    602640            {
    603                 get_bits1(gb);  // scaling_list
     641                if(get_bits1(gb)) // Scaling list presnent
     642                {
     643                    int sl_n = ((idx < 6) ? 16 : 64);
     644                    for(int sl_i = 0; sl_i < sl_n; sl_i++)
     645                    {
     646                        get_se_golomb(gb);
     647                    }
     648                }
    604649            }
    605650        }
    606651    }
    void H264Parser::vui_parameters(GetBitContext * gb) 
    10151060
    10161061uint H264Parser::frameRate(void) const
    10171062{
    1018     uint64_t    num;
     1063    uint64_t    num;
    10191064    uint64_t    fps;
    10201065
    10211066    num   = 500 * (uint64_t)timeScale; /* 1000 * 0.5 */
  • mythtv/libs/libmythtv/mpeg/H264Parser.h

    diff --git a/mythtv/libs/libmythtv/mpeg/H264Parser.h b/mythtv/libs/libmythtv/mpeg/H264Parser.h
    index 2117a96..d737741 100644
    a b class H264Parser { 
    101101    };
    102102
    103103    H264Parser(void);
    104     ~H264Parser(void) {;}
     104    ~H264Parser(void) {delete [] rbsp_buffer;}
    105105
    106106    uint32_t addBytes(const uint8_t  *bytes,
    107107                      const uint32_t  byte_count,
    class H264Parser { 
    168168        }
    169169
    170170    bool new_AU(void);
     171    uint32_t load_rbsp(const uint8_t *byteP, uint32_t byte_count);
    171172    bool decode_Header(GetBitContext *gb);
    172173    void decode_SPS(GetBitContext *gb);
    173174    void decode_PPS(GetBitContext * gb);
    class H264Parser { 
    181182    bool       I_is_keyframe;
    182183
    183184    uint32_t   sync_accumulator;
     185    uint8_t   *rbsp_buffer;
     186    uint32_t   rbsp_buffer_size;
    184187    GetBitContext gb;
    185188
    186189    int        prev_frame_num, frame_num;