| 3633 | } |
| 3634 | |
| 3635 | static int update_ps_streams( hb_stream_t * stream, int stream_id, int stream_id_ext, int stream_type, int in_kind ) |
| 3636 | { |
| 3637 | int ii; |
| 3638 | int same_stream = -1; |
| 3639 | kind_t kind = in_kind == -1 ? st2codec[stream_type].kind : in_kind; |
| 3640 | |
| 3641 | for ( ii = 0; ii < stream->pes.count; ii++ ) |
| 3642 | { |
| 3643 | if ( stream->pes.list[ii].stream_id == stream_id ) |
| 3644 | same_stream = ii; |
| 3645 | |
| 3646 | if ( stream->pes.list[ii].stream_id == stream_id && |
| 3647 | stream->pes.list[ii].stream_id_ext == 0 && |
| 3648 | stream->pes.list[ii].stream_kind == U ) |
| 3649 | { |
| 3650 | // This is an unknown stream type that hasn't been |
| 3651 | // given a stream_id_ext. So match only to stream_id |
| 3652 | // |
| 3653 | // is the stream_id_ext being updated? |
| 3654 | if ( stream_id_ext != 0 ) |
| 3655 | break; |
| 3656 | |
| 3657 | // If stream is already in the list and the new 'kind' is |
| 3658 | // PCR, Unknown, or same as before, just return the index |
| 3659 | // to the entry found. |
| 3660 | if ( kind == P || kind == U || kind == stream->pes.list[ii].stream_kind ) |
| 3661 | return ii; |
| 3662 | // Update stream_type and kind |
| 3663 | break; |
| 3664 | } |
| 3665 | if ( stream_id == stream->pes.list[ii].stream_id && |
| 3666 | stream_id_ext == stream->pes.list[ii].stream_id_ext ) |
| 3667 | { |
| 3668 | // If stream is already in the list and the new 'kind' is |
| 3669 | // PCR and the old 'kind' is unknown, set the new 'kind' |
| 3670 | if ( kind == P && stream->pes.list[ii].stream_kind == U ) |
| 3671 | break; |
| 3672 | |
| 3673 | // If stream is already in the list and the new 'kind' is |
| 3674 | // PCR, Unknown, or same as before, just return the index |
| 3675 | // to the entry found. |
| 3676 | if ( kind == P || kind == U || kind == stream->pes.list[ii].stream_kind ) |
| 3677 | return ii; |
| 3678 | // Replace unknown 'kind' with known 'kind' |
| 3679 | break; |
| 3680 | } |
| 3681 | // Resolve multiple videos |
| 3682 | if ( kind == V && stream->pes.list[ii].stream_kind == V ) |
| 3683 | { |
| 3684 | if ( stream_id <= stream->pes.list[ii].stream_id && |
| 3685 | stream_id_ext <= stream->pes.list[ii].stream_id_ext ) |
| 3686 | { |
| 3687 | // Assume primary video stream has the smallest stream id |
| 3688 | // and only use the primary. move the current item |
| 3689 | // to the end of the list. we want to keep it for |
| 3690 | // debug and informational purposes. |
| 3691 | int jj = new_pes( stream ); |
| 3692 | memcpy( &stream->pes.list[jj], &stream->pes.list[ii], |
no test coverage detected