stream_component_open
来源:互联网 发布:原子车车架数据 编辑:程序博客网 时间:2024/06/08 07:42
转自http://blog.csdn.net/mydeardingxiaoli/article/details/17224629
1、主要步骤
- static int stream_component_open(VideoState *is, int stream_index)
- {
- //依照编解码上下文的codec_id,遍历编解码器链表,找到相应的解码器
- codec = avcodec_find_decoder(enc->codec_id);
- //打开编解码器,初始化具体编解码器的运行环境。
- if (!codec || avcodec_open(enc, codec) < 0)
- return -1;
- switch(enc->codec_type)
- {
- /* prepare audio */
- case CODEC_TYPE_AUDIO:
- //初始化音频队列
- packet_queue_init(&is->audioq);
- //启动广义的音频解码线程。
- wanted_spec.callback = sdl_audio_callback;
- wanted_spec.userdata = is;
- if (SDL_OpenAudio(&wanted_spec, &spec) < 0) {
- fprintf(stderr, "SDL_OpenAudio: %s\n", SDL_GetError());
- return -1;
- }
- SDL_PauseAudio(0);
- break;
- case CODEC_TYPE_VIDEO:
- //初始化视频队列
- packet_queue_init(&is->videoq);
- //启动视频解码线程
- is->video_tid = SDL_CreateThread(video_thread, is);
- break;
- case CODEC_TYPE_SUBTITLE:
- packet_queue_init(&is->subtitleq);
- is->subtitle_tid = SDL_CreateThread(subtitle_thread, is);
- break;
- default:
- break;
- }
- return 0;
- }
2、具体代码(解码线程)
- static int stream_component_open(VideoState *is, int stream_index)
- {
- AVFormatContext *ic = is->ic;
- AVCodecContext *enc;
- AVCodec *codec;
- <strong>SDL_AudioSpec wanted_spec, spec;</strong>
- if (stream_index < 0 || stream_index >= ic->nb_streams)
- return -1;
- enc = ic->streams[stream_index]->codec;
- /* prepare audio output */
- if (enc->codec_type == CODEC_TYPE_AUDIO) { //如果为音频解码,需要初始化参数
- if (enc->channels > 0) {
- enc->request_channels = FFMIN(2, enc->channels);
- } else {
- enc->request_channels = 2;
- }
- }
- codec = avcodec_find_decoder(enc->codec_id); //根据id找到具体的解码器
- enc->debug_mv = debug_mv;
- enc->debug = debug;
- enc->workaround_bugs = workaround_bugs;
- enc->lowres = lowres;
- if(lowres) enc->flags |= CODEC_FLAG_EMU_EDGE;
- enc->idct_algo= idct;
- if(fast) enc->flags2 |= CODEC_FLAG2_FAST;
- enc->skip_frame= skip_frame;
- enc->skip_idct= skip_idct;
- enc->skip_loop_filter= skip_loop_filter;
- enc->error_recognition= error_recognition;
- enc->error_concealment= error_concealment;
- set_context_opts(enc, avctx_opts[enc->codec_type], 0); //set decode option
- if (!codec ||
- avcodec_open(enc, codec) < 0) //open decode
- return -1;
- /* prepare audio output */
- if (enc->codec_type == CODEC_TYPE_AUDIO) {
- wanted_spec.freq = enc->sample_rate;
- wanted_spec.format = AUDIO_S16SYS;
- wanted_spec.channels = enc->channels;
- wanted_spec.silence = 0;
- wanted_spec.samples = SDL_AUDIO_BUFFER_SIZE;
- wanted_spec.callback = <strong><span style="color:#ff0000;">sdl_audio_callback</span></strong>; //此处初始化了一个音频解码线程(线程是在SDL中实现的,此接口是对用户提供了一个回调函数接口)
- wanted_spec.userdata = is;
- if (SDL_OpenAudio(&wanted_spec, &spec) < 0) {
- fprintf(stderr, "SDL_OpenAudio: %s\n", SDL_GetError());
- return -1;
- }
- is->audio_hw_buf_size = spec.size;
- is->audio_src_fmt= SAMPLE_FMT_S16;
- }
- if(thread_count>1)
- avcodec_thread_init(enc, thread_count); //解码线程初始化
- enc->thread_count= thread_count;
- ic->streams[stream_index]->discard = AVDISCARD_DEFAULT;
- switch(enc->codec_type) {
- case CODEC_TYPE_AUDIO:
- is->audio_stream = stream_index;
- is->audio_st = ic->streams[stream_index];
- is->audio_buf_size = 0;
- is->audio_buf_index = 0;
- /* init averaging filter */
- is->audio_diff_avg_coef = exp(log(0.01) / AUDIO_DIFF_AVG_NB);
- is->audio_diff_avg_count = 0;
- /* since we do not have a precise anough audio fifo fullness,
- we correct audio sync only if larger than this threshold */
- is->audio_diff_threshold = 2.0 * SDL_AUDIO_BUFFER_SIZE / enc->sample_rate;
- memset(&is->audio_pkt, 0, sizeof(is->audio_pkt));
- packet_queue_init(&is->audioq);
- SDL_PauseAudio(0);
- break;
- case CODEC_TYPE_VIDEO:
- is->video_stream = stream_index;
- is->video_st = ic->streams[stream_index];
- is->frame_last_delay = 40e-3;
- is->frame_timer = (double)av_gettime() / 1000000.0;
- is->video_current_pts_time = av_gettime();
- packet_queue_init(&is->videoq);
- is->video_tid = SDL_CreateThread(video_thread, is); //如果为视频,则创建一个视频处理线程
- break;
- case CODEC_TYPE_SUBTITLE:
- is->subtitle_stream = stream_index;
- is->subtitle_st = ic->streams[stream_index];
- packet_queue_init(&is->subtitleq);
- is->subtitle_tid = SDL_CreateThread(subtitle_thread, is);
- break;
- default:
- break;
- }
- return 0;
- }
0 0
- stream_component_open
- stream_component_open的主要步骤
- ffplay中stream_component_open()函数分析
- ffplay中stream_component_open()函数分析
- 时间类型转换-指定年的第几周开始时间和结束时间
- awk语法学习
- Maven中的DependencyManagement和Dependencies
- C++中的sort()和qsort()和C中的二维数组传参
- RedHat下安装mysql5.8
- stream_component_open
- 如何用eclispe远程调试tomcat
- github Host key verification failed
- Personal diary of MrWangc (0)
- 计算机网络(六)---IP多播
- 虚拟机 3种网络连接方式区别
- java中各种集合的用法和比较
- Android之SurfaceView学习(一)
- 【POJ2140】Herd Sums(数学)