全部博文(24)
分类: LINUX
2013-03-19 11:02:40
/* read the first 1024 bytes to get packet size */上面这几行代码是从数据流当中读了5 * 1024个字节来判断数据包的大小raw_packet_size,一般这个值是188,当然如果这个ts流不是标准和dvb ts流的话,那当然会不一样的。
pos = url_ftell(pb);
len = get_buffer(pb, buf, sizeof(buf));
if (len != sizeof(buf))
goto fail;
ts->raw_packet_size = get_packet_size(buf, sizeof(buf));
if (ts->raw_packet_size <= 0)
goto fail;
/* first do a scaning to get all the services */上面这几行代码是扫描节目信息,首先mpegts_scan_sdt当中调用mpegts_open_section_filter设置了一个SDT表的filter,SDT表当中会有节目的名子,提供商名子等等。接着在mpegts_set_service当中又设置mpegts_open_section_filter设置了一个PAT表filter,PAT表当中会存放节目的SID, PMT_PID,从而可以取到对应的PMT表,然后解板出VIDEO PID, AUDIO PID来,handle_packets就不用看了,上面设置了filter,这里紧跟着就得让filter工作起来了。
url_fseek(pb, pos, SEEK_SET);
mpegts_scan_sdt(ts);
mpegts_set_service(ts);
handle_packets(ts, s->probesize);
/* if could not find service, enable auto_guess */
ts->auto_guess = 1;
……pmt_cb:
av_new_program(ts->stream, sid);
ts->stop_parse--;
mpegts_open_section_filter(ts, pmt_pid, pmt_cb, ts, 1);
add_pat_entry(ts, sid);
add_pid_to_pmt(ts, sid, 0); //add pat pid to program
add_pid_to_pmt(ts, sid, pmt_pid);
……
……
/* now create ffmpeg stream */
switch(stream_type) {得到每个video, audio的PID,然后就设置成pes filter,到这里基本上获取流的基本信息就已经结束了。下面再来看使用最多的一个函数mpegts_read_packet:
case STREAM_TYPE_AUDIO_MPEG1:
case STREAM_TYPE_AUDIO_MPEG2:
case STREAM_TYPE_VIDEO_MPEG1:
case STREAM_TYPE_VIDEO_MPEG2:
case STREAM_TYPE_VIDEO_MPEG4:
case STREAM_TYPE_VIDEO_H264:
case STREAM_TYPE_VIDEO_VC1:
case STREAM_TYPE_VIDEO_DIRAC:
case STREAM_TYPE_AUDIO_AAC:
case STREAM_TYPE_AUDIO_AC3:
case STREAM_TYPE_AUDIO_DTS:
case STREAM_TYPE_AUDIO_HDMV_DTS:
case STREAM_TYPE_SUBTITLE_DVB:
if((stream_type == STREAM_TYPE_AUDIO_HDMV_DTS && !has_hdmv_descr)
|| (stream_type == STREAM_TYPE_VIDEO_DIRAC && !has_dirac_descr))
break;
if(ts->pids[pid] && ts->pids[pid]->type == MPEGTS_PES){
pes= ts->pids[pid]->u.pes_filter.opaque;
st= pes->st;
}else{
if (ts->pids[pid]) mpegts_close_filter(ts, ts->pids[pid]); //wrongly added sdt filter probably
pes = add_pes_stream(ts, pid, pcr_pid, stream_type);
if (pes)
st = new_pes_av_stream(pes, 0);
}
add_pid_to_pmt(ts, h->id, pid);
if(st)
av_program_add_stream_index(ts->stream, h->id, st->index);
break;
default:
/* we ignore the other streams */
break;
}
……