private void Clear() { format_context = null; p_avformat_context = IntPtr.Zero; p_video_codec = IntPtr.Zero; p_audio_codec = IntPtr.Zero; video_stream_index = -1; audio_stream_index = -1; video_codec_context = null; audio_codec_context = null; video_stream = null; audio_stream = null; p_frame = IntPtr.Zero; p_frame_rgb = IntPtr.Zero; p_packet = IntPtr.Zero; if (p_audio_buffer != IntPtr.Zero) { Marshal.FreeHGlobal(p_audio_buffer); p_audio_buffer = IntPtr.Zero; } video_buffer_manager_ = null; audio_buffer_manager_ = null; video_rate_ = 24; video_scale_ = 1; key_frame_list_ = new List <int>(); key_dts_list_ = new List <long>(); current_frame_ = 0; last_requested_frame_ = 0; audio_priority_times_ = 0; av_packet_queue_ = new Queue <PacketContainer>(); thread_end_event_ = new ManualResetEvent(true); command_queue_ = new List <Command>(); fixed_video_width_ = -1; fixed_video_height_ = -1; }
private void OpenCodec(string filename) { AVCodecAPI.av_register_all(); int error_code = AVCodecAPI.av_open_input_file(out p_avformat_context, filename, IntPtr.Zero, 0, IntPtr.Zero); if (error_code != 0) { throw new AVCodecCannotOpenFileException(); } error_code = AVCodecAPI.av_find_stream_info(p_avformat_context); if (error_code < 0) { throw new AVCodecException(); } format_context = (AVFormatContext)Marshal.PtrToStructure(p_avformat_context, typeof(AVFormatContext)); for (int i = 0; i < format_context.nb_streams; ++i) { AVStream stream = (AVStream)Marshal.PtrToStructure(format_context.streams[i], typeof(AVStream)); AVCodecContext temp_codec_context = (AVCodecContext)Marshal.PtrToStructure(stream.codec, typeof(AVCodecContext)); if (temp_codec_context.codec_type == 0) { if (video_stream_index < 0) { video_stream_index = i; video_stream = stream; video_codec_context = temp_codec_context; } } else if (temp_codec_context.codec_type == 1) { if (audio_stream_index < 0) { audio_stream_index = i; audio_stream = stream; audio_codec_context = temp_codec_context; } } } if (video_stream_index >= 0) { p_video_codec = AVCodecAPI.avcodec_find_decoder(video_codec_context.codec_id); error_code = AVCodecAPI.avcodec_open(video_stream.codec, p_video_codec); if (error_code < 0) { throw new AVCodecException(); } } if (audio_stream_index >= 0) { p_audio_codec = AVCodecAPI.avcodec_find_decoder(audio_codec_context.codec_id); error_code = AVCodecAPI.avcodec_open(audio_stream.codec, p_audio_codec); if (error_code < 0) { throw new AVCodecException(); } } }