public override int GetHashCode() { unchecked { var hashCode = Width; hashCode = (hashCode * 397) ^ Height; hashCode = (hashCode * 397) ^ (CodecName != null ? CodecName.GetHashCode() : 0); hashCode = (hashCode * 397) ^ StartTime.GetHashCode(); return(hashCode); } }
public override int GetHashCode() { unchecked { var hashCode = (CodecName != null ? CodecName.GetHashCode() : 0); hashCode = (hashCode * 397) ^ StartTime.GetHashCode(); hashCode = (hashCode * 397) ^ Channels; hashCode = (hashCode * 397) ^ (ChannelLayout != null ? ChannelLayout.GetHashCode() : 0); return(hashCode); } }
public VideoStreamDecoder(string url, AVHWDeviceType HWDeviceType = AVHWDeviceType.AV_HWDEVICE_TYPE_NONE) { _pFormatContext = ffmpeg.avformat_alloc_context(); _receivedFrame = ffmpeg.av_frame_alloc(); var pFormatContext = _pFormatContext; ffmpeg.avformat_open_input(&pFormatContext, url, null, null).ThrowExceptionIfError(); AVCodec * codec = null; AVBufferRef *codecBuff = null; if (HWDeviceType is AVHWDeviceType.AV_HWDEVICE_TYPE_QSV) { codec = ffmpeg.avcodec_find_decoder_by_name("h264_qsv"); codec->id = AVCodecID.AV_CODEC_ID_H264; for (int i = 0; i < _pFormatContext->nb_streams; i++) { AVStream *st = _pFormatContext->streams[i]; if (st->codecpar->codec_id == AVCodecID.AV_CODEC_ID_H264 && _videoStream == null) { _videoStream = st; Console.WriteLine("Stream founded!"); } else { st->discard = AVDiscard.AVDISCARD_ALL; } } _streamIndex = _videoStream->index; } else { _streamIndex = ffmpeg.av_find_best_stream(_pFormatContext, AVMediaType.AVMEDIA_TYPE_VIDEO, -1, -1, &codec, 0); } _pCodecContext = ffmpeg.avcodec_alloc_context3(codec); if (HWDeviceType != AVHWDeviceType.AV_HWDEVICE_TYPE_NONE) { if (ffmpeg.av_hwdevice_ctx_create(&_pCodecContext->hw_device_ctx, HWDeviceType, "auto", null, 0) < 0) { throw new Exception("HW device init ERROR!"); } else { Console.WriteLine("Device " + HWDeviceType + " init OK"); isHwAccelerate = true; } } if (_pCodecContext == null) { throw new Exception("Codec init error"); } ffmpeg.avformat_find_stream_info(_pFormatContext, null); //This is necessary to determine the parameters of online broadcasting if (_videoStream->codecpar->extradata != null) { int size = (int)(_videoStream->codecpar->extradata_size); _pCodecContext->extradata = (byte *)ffmpeg.av_mallocz((ulong)size + ffmpeg.AV_INPUT_BUFFER_PADDING_SIZE); _pCodecContext->extradata_size = (int)size + ffmpeg.AV_INPUT_BUFFER_PADDING_SIZE; FFmpegHelper.memcpy((IntPtr)_pCodecContext->extradata, (IntPtr)_videoStream->codecpar->extradata, size); //Or just /*for (int i = 0; i < size; i++) * _pCodecContext->extradata[i] = _videoStream->codecpar->extradata[i];*/ } if (HWDeviceType == AVHWDeviceType.AV_HWDEVICE_TYPE_QSV) { _pCodecContext->get_format = get_fmt; } ffmpeg.avcodec_parameters_to_context(_pCodecContext, _videoStream->codecpar); ffmpeg.avcodec_open2(_pCodecContext, codec, null); CodecName = ffmpeg.avcodec_get_name(codec->id); FrameSize = new Size(_videoStream->codecpar->width, _videoStream->codecpar->height); PixelFormat = _pCodecContext->sw_pix_fmt; //It doesn't work (== AV_HWDEVICE_TYPE_NONE before the first frame) Console.WriteLine("Codec: " + CodecName.ToString()); Console.WriteLine("Size: " + FrameSize.ToString()); Console.WriteLine("PixelFormat: " + PixelFormat.ToString()); _pPacket = ffmpeg.av_packet_alloc(); _pFrame = ffmpeg.av_frame_alloc(); }