PageRenderTime 27ms CodeModel.GetById 13ms app.highlight 10ms RepoModel.GetById 1ms app.codeStats 0ms

/ts/pat.c

https://bitbucket.org/a84/gs_public/
C | 31 lines | 25 code | 5 blank | 1 comment | 2 complexity | 883a8a54e9fa98ed55d002dc5f3eef8b MD5 | raw file
 1#include "pat.h"
 2
 3mpeg2_psi_t *mpeg2_pat_alloc(mpeg2_psi_t *buffer, uint16_t stream_id, uint8_t version) {
 4	mpeg2_psi_t *ptr = (buffer) ? buffer : (mpeg2_psi_t *)malloc(sizeof(mpeg2_psi_t));
 5    if(!ptr) return NULL;
 6    memset(ptr->payload, 0, sizeof(ptr->payload));
 7    ptr->payload_size = sizeof(mpeg2_pat_header_t);
 8    ptr->skip = 0;
 9
10    mpeg2_pat_header_t *ph = (mpeg2_pat_header_t *)ptr->payload;
11//    SET_I8(ph->table_id, 0x00);
12    SET_I8(ph->syntax, 1);
13    SET_I16(ph->stream_id, stream_id);
14    SET_I8(ph->version, version);
15    SET_I8(ph->current_next, 1);    // current
16
17    return ptr;
18}
19
20void mpeg2_pat_free(mpeg2_psi_t *pat_p) {
21    if(pat_p) free(pat_p);
22}
23
24void mpeg2_pat_add_pmt(mpeg2_psi_t *pat_p, uint16_t pnr, uint16_t pid) {
25	mpeg2_pat_header_t *ph = (mpeg2_pat_header_t *)pat_p->payload;
26	mpeg2_pat_pmt_t *pp = (mpeg2_pat_pmt_t *)&pat_p->payload[pat_p->payload_size];
27    SET_I16(pp->pnr, pnr);
28    SET_I16(pp->pid, pid);
29    pat_p->payload_size += sizeof(mpeg2_pat_pmt_t);
30    SET_I16(ph->slen, (pat_p->payload_size - 3));
31}