diff --git a/tests/H264Decoder.h b/tests/FFMpegDecoder.h similarity index 78% rename from tests/H264Decoder.h rename to tests/FFMpegDecoder.h index 31dd8229..465a87de 100644 --- a/tests/H264Decoder.h +++ b/tests/FFMpegDecoder.h @@ -13,6 +13,7 @@ #include #include #include +#include "Extension/Frame.h" #ifdef __cplusplus extern "C" { #endif @@ -27,14 +28,24 @@ using namespace std; namespace mediakit { -class H264Decoder -{ +class FFMpegDecoder{ public: - H264Decoder(void){ + FFMpegDecoder(int codec_id){ + auto ff_codec_id = AV_CODEC_ID_H264; + switch (codec_id){ + case CodecH264: + ff_codec_id = AV_CODEC_ID_H264; + break; + case CodecH265: + ff_codec_id = AV_CODEC_ID_H265; + break; + default: + throw std::invalid_argument("不支持该编码格式"); + } avcodec_register_all(); - AVCodec *pCodec = avcodec_find_decoder(AV_CODEC_ID_H264); + AVCodec *pCodec = avcodec_find_decoder(ff_codec_id); if (!pCodec) { - throw std::runtime_error("未找到H264解码器"); + throw std::runtime_error("未找到解码器"); } m_pContext.reset(avcodec_alloc_context3(pCodec), [](AVCodecContext *pCtx) { avcodec_close(pCtx); @@ -57,7 +68,7 @@ public: throw std::runtime_error("创建帧缓存失败"); } } - virtual ~H264Decoder(void){} + virtual ~FFMpegDecoder(void){} bool inputVideo(unsigned char* data,unsigned int dataSize,uint32_t ui32Stamp,AVFrame **ppFrame){ AVPacket pkt; av_init_packet(&pkt); diff --git a/tests/test_player.cpp b/tests/test_player.cpp index ed15f8b5..2954a43c 100644 --- a/tests/test_player.cpp +++ b/tests/test_player.cpp @@ -1,4 +1,4 @@ -/* +/* * Copyright (c) 2016 The ZLMediaKit project authors. All Rights Reserved. * * This file is part of ZLMediaKit(https://github.com/xiongziliang/ZLMediaKit). @@ -12,13 +12,12 @@ #include "Util/util.h" #include "Util/logger.h" #include -#include "Poller/EventPoller.h" #include "Rtsp/UDPServer.h" #include "Player/MediaPlayer.h" #include "Util/onceToken.h" -#include "H264Decoder.h" +#include "FFMpegDecoder.h" #include "YuvDisplayer.h" -#include "Network/sockutil.h" +#include "Extension/H265.h" using namespace std; using namespace toolkit; @@ -111,8 +110,8 @@ int main(int argc, char *argv[]) { } auto viedoTrack = strongPlayer->getTrack(TrackVideo); - if (!viedoTrack || viedoTrack->getCodecId() != CodecH264) { - WarnL << "没有视频或者视频不是264编码!"; + if (!viedoTrack) { + WarnL << "没有视频!"; return; } @@ -123,24 +122,21 @@ int main(int argc, char *argv[]) { auto &displayer = (*storage)["displayer"]; auto &merger = (*storage)["merger"]; if(!decoder){ - decoder.set(); + decoder.set(frame->getCodecId()); } if(!displayer){ displayer.set(nullptr,url); } if(!merger){ merger.set(); - }; - + } merger.get().inputFrame(frame,[&](uint32_t dts,uint32_t pts,const Buffer::Ptr &buffer){ AVFrame *pFrame = nullptr; - bool flag = decoder.get().inputVideo((unsigned char *) buffer->data(), buffer->size(), dts, &pFrame); + bool flag = decoder.get().inputVideo((unsigned char *) buffer->data(), buffer->size(), dts, &pFrame); if (flag) { displayer.get().displayYUV(pFrame); } }); - - return true; }); }));