Changeset 805a9ad61bb628aee2ca936d048a86f16503bc56

Show
Ignore:
Timestamp:
03/14/08 10:10:03 (6 months ago)
Author:
Rafaël Carré <funman@videolan.org>
git-committer:
Rafaël Carré <funman@videolan.org> 1205485803 +0100
git-parent:

[62d91d413bc4a7c52a8b598680db14a19e523291]

git-author:
Rafaël Carré <funman@videolan.org> 1205485660 +0100
Message:

Fix AAC muxing into TS

Add ADTS headers on top of the raw AAC frames
Use the ADTS stream type (0x0f) since LOAS isn't implemented

This was wrong since we were streaming raw, not LOAS/LATM

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • modules/mux/mpeg/ts.c

    r4ce76d3 r805a9ad  
    460460 
    461461static block_t *FixPES( sout_mux_t *p_mux, block_fifo_t *p_fifo ); 
     462static block_t *Add_ADTS( block_t *, es_format_t * ); 
    462463static void TSSchedule  ( sout_mux_t *p_mux, sout_buffer_chain_t *p_chain_ts, 
    463464                          mtime_t i_pcr_length, mtime_t i_pcr_dts ); 
     
    973974                    break; 
    974975                case VLC_FOURCC( 'm', 'p','4', 'a' ): 
    975                     p_stream->i_stream_type = 0x11; 
     976                    /* XXX: make that configurable in some way when LOAS 
     977                     * is implemented for AAC in TS */ 
     978                    //p_stream->i_stream_type = 0x11; /* LOAS/LATM */ 
     979                    p_stream->i_stream_type = 0x0f; /* ADTS */ 
    976980                    p_stream->i_stream_id = 0xfa; 
    977981                    p_sys->i_mpeg4_streams++; 
     
    13961400                         || p_input->p_fmt->i_codec != 
    13971401                             VLC_FOURCC('m', 'p', 'g', 'a') ) 
     1402                    { 
    13981403                        p_data = block_FifoGet( p_input->p_fifo ); 
     1404 
     1405                        if( p_input->p_fmt->i_codec == 
     1406                                VLC_FOURCC('m', 'p', '4', 'a' ) ) 
     1407                            p_data = Add_ADTS( p_data, p_input->p_fmt ); 
     1408                    } 
    13991409                    else 
    14001410                        p_data = FixPES( p_mux, p_input->p_fifo ); 
     
    16561666{ 
    16571667    block_t *p_data; 
    1658     int i_size; 
     1668    size_t i_size; 
    16591669 
    16601670    p_data = block_FifoShow( p_fifo ); 
     
    17131723        return p_data; 
    17141724    } 
     1725} 
     1726 
     1727static block_t *Add_ADTS( block_t *p_data, es_format_t *p_fmt ) 
     1728{ 
     1729    uint8_t *p_extra = p_fmt->p_extra; 
     1730 
     1731    if( !p_data || p_fmt->i_extra < 2 || !p_extra ) 
     1732        return p_data; /* no data to construct the headers */ 
     1733 
     1734    int i_index = ( (p_extra[0] << 1) | (p_extra[1] >> 7) ) & 0x0f; 
     1735    int i_profile = (p_extra[0] >> 3) - 1; /* i_profile < 4 */ 
     1736 
     1737    if( i_index == 0x0f && p_fmt->i_extra < 5 ) 
     1738        return p_data; /* not enough data */ 
     1739 
     1740    int i_channels = (p_extra[i_index == 0x0f ? 4 : 1] >> 3) & 0x0f; 
     1741 
     1742#define ADTS_HEADER_SIZE 7 /* CRC needs 2 more bytes */ 
     1743 
     1744 
     1745    /* keep a copy in case block_Realloc() fails */ 
     1746    block_t *p_bak_block = block_Duplicate( p_data ); 
     1747    if( !p_bak_block ) /* OOM, block_Realloc() is likely to lose our block */ 
     1748        return p_data; /* the frame isn't correct but that's the best we have */ 
     1749 
     1750    block_t *p_new_block = block_Realloc( p_data, ADTS_HEADER_SIZE, 
     1751                                            p_data->i_buffer ); 
     1752    if( !p_new_block ) 
     1753        return p_bak_block; /* OOM, send the (incorrect) original frame */ 
     1754 
     1755    block_Release( p_bak_block ); /* we don't need the copy anymore */ 
     1756 
     1757 
     1758    uint8_t *p_buffer = p_new_block->p_buffer; 
     1759 
     1760    /* fixed header */ 
     1761    p_buffer[0] = 0xff; 
     1762    p_buffer[1] = 0xf1; /* 0xf0 | 0x00 | 0x00 | 0x01 */ 
     1763    p_buffer[2] = (i_profile << 6) | ((i_index & 0x0f) << 2) | ((i_channels >> 2) & 0x01) ; 
     1764    p_buffer[3] = (i_channels << 6) | ((p_data->i_buffer >> 11) & 0x03); 
     1765 
     1766    /* variable header (starts at last 2 bits of 4th byte) */ 
     1767 
     1768    int i_fullness = 0x7ff; /* 0x7ff means VBR */ 
     1769    /* XXX: We should check if it's CBR or VBR, but no known implementation 
     1770     * do that, and it's a pain to calculate this field */ 
     1771 
     1772    p_buffer[4] = p_data->i_buffer >> 3; 
     1773    p_buffer[5] = ((p_data->i_buffer & 0x07) << 5) | ((i_fullness >> 6) & 0x1f); 
     1774    p_buffer[6] = ((i_fullness & 0x3f) << 2) /* | 0xfc */; 
     1775 
     1776    return p_new_block; 
    17151777} 
    17161778