int main(int argc, char *argv[])
{
    if(argc < 2) {
        std::cout << USAGE << std::endl;
        exit(1);
    }
    std::ifstream  ifs;
    char *inp_filename = argv[1];
    unsigned char  ts_pkt[256];
    int  n_pkts = 0;
    uint64_t       curr_pcr;
    uint64_t       pcr_ext;
    int            inp_pid;

    ifs.open(inp_filename, std::ios::in);
    if(!ifs.is_open()) {
        std::cout << "Unable to open " << inp_filename;
        exit(1);
    }

    while(!ifs.eof()) {
        ifs.read((char*)ts_pkt, 188);
        inp_pid = ts_get_pid(ts_pkt);

        if(ts_has_adaptation(ts_pkt))
        {
            printf("Adaptation=%d\n", (ts_pkt[3] & 0x30) >> 4);
            if(tsaf_has_discontinuity(ts_pkt))
            {
                printf("PCR Discontinuity %ld %d %d\n", (int64_t)ifs.tellg()/188, inp_pid, ts_get_adaptation(ts_pkt));
            }
        }
        if(ts_has_adaptation(ts_pkt) && ts_get_adaptation(ts_pkt) > 0)
        {

            if(tsaf_has_pcr(ts_pkt))
            {
                curr_pcr = tsaf_get_pcr(ts_pkt);
                pcr_ext = tsaf_get_pcrext(ts_pkt);
                curr_pcr = (300 * curr_pcr) + pcr_ext;
                printf("%d %lld %lld %d\n", inp_pid, curr_pcr/(300 * 90), (int64_t)ifs.tellg()/188, ts_get_unitstart(ts_pkt));
            }
        }
        n_pkts++;
        //std::cout << n_pkts <<std::endl;
    }
    std::cout << "Completed" << std::endl;
}
Exemple #2
0
/*****************************************************************************
 * output_Put : called from demux
 *****************************************************************************/
void output_Put( output_t *p_output, block_t *p_block )
{
    int i_block_cnt = output_BlockCount( p_output );
    packet_t *p_packet;

    p_block->i_refcount++;

    if ( p_output->p_last_packet != NULL
          && p_output->p_last_packet->i_depth < i_block_cnt
          && p_output->p_last_packet->i_dts + p_output->config.i_max_retention
              > p_block->i_dts )
    {
        p_packet = p_output->p_last_packet;
        if ( ts_has_adaptation( p_block->p_ts )
              && ts_get_adaptation( p_block->p_ts )
              && tsaf_has_pcr( p_block->p_ts ) )
            p_packet->i_dts = p_block->i_dts;
    }
    else
    {
        /* This isn't the cleanest allocation of the world. */
        p_packet = malloc( sizeof(packet_t)
                            + (i_block_cnt - 1) * sizeof(block_t *) );
        p_packet->pp_blocks = &p_packet->p_blocks;
        p_packet->i_depth = 0;
        p_packet->p_next = NULL;
        p_packet->i_dts = p_block->i_dts;
        if ( p_output->p_last_packet != NULL )
            p_output->p_last_packet->p_next = p_packet;
        else
            p_output->p_packets = p_packet;
        p_output->p_last_packet = p_packet;
    }

    p_packet->pp_blocks[p_packet->i_depth] = p_block;
    p_packet->i_depth++;
}
Exemple #3
0
/** @internal @This handles input buffers.
 *
 * @param upipe description structure of the pipe
 * @param uref input buffer to handle
 * @param upump_p reference to the pump that generated the buffer
 */
static void upipe_dvbcsa_enc_input(struct upipe *upipe,
                                   struct uref *uref,
                                   struct upump **upump_p)
{
    struct upipe_dvbcsa_enc *upipe_dvbcsa_enc =
        upipe_dvbcsa_enc_from_upipe(upipe);
    struct upipe_dvbcsa_common *common =
        upipe_dvbcsa_enc_to_common(upipe_dvbcsa_enc);

    if (unlikely(!upipe_dvbcsa_enc->key))
        /* no key set, forward */
        return upipe_dvbcsa_enc_output(upipe, uref, upump_p);

    uint32_t ts_header_size = TS_HEADER_SIZE;
    uint8_t buf[TS_HEADER_SIZE];
    const uint8_t *ts_header = uref_block_peek(uref, 0, sizeof (buf), buf);
    if (unlikely(!ts_header)) {
        upipe_err(upipe, "fail to read ts header");
        uref_free(uref);
        return;
    }
    uint8_t scrambling = ts_get_scrambling(ts_header);
    bool has_payload = ts_has_payload(ts_header);
    bool has_adaptation = ts_has_adaptation(ts_header);
    uint16_t pid = ts_get_pid(ts_header);
    uref_block_peek_unmap(uref, 0, buf, ts_header);

    if (!has_payload || scrambling ||
        !upipe_dvbcsa_common_check_pid(common, pid))
        return upipe_dvbcsa_enc_output(upipe, uref, upump_p);

    if (unlikely(has_adaptation)) {
        uint8_t af_length;
        int ret = uref_block_extract(uref, ts_header_size, 1, &af_length);
        if (unlikely(!ubase_check(ret))) {
            upipe_err(upipe, "fail to extract adaptation field length");
            uref_free(uref);
            return;
        }
        if (unlikely(af_length >= 183)) {
            upipe_warn(upipe, "invalid adaptation field received");
            uref_free(uref);
            return;
        }
        ts_header_size += af_length + 1;
    }

    struct ubuf *ubuf = ubuf_block_copy(uref->ubuf->mgr, uref->ubuf, 0, -1);
    if (unlikely(!ubuf)) {
        upipe_err(upipe, "fail to allocate buffer");
        uref_free(uref);
        return;
    }
    uref_attach_ubuf(uref, ubuf);
    int size = -1;
    uint8_t *ts;
    int ret = ubuf_block_write(ubuf, 0, &size, &ts);
    if (unlikely(!ubase_check(ret))) {
        upipe_err(upipe, "fail to write buffer");
        uref_free(uref);
        return;
    }
    ts_set_scrambling(ts, 0x2);
    dvbcsa_encrypt(upipe_dvbcsa_enc->key,
                   ts + ts_header_size,
                   size - ts_header_size);
    return upipe_dvbcsa_enc_output(upipe, uref, upump_p);
}