Skip to content
Snippets Groups Projects
Commit c05dfb14 authored by Pierre Lespagnol's avatar Pierre Lespagnol Committed by Adrien Béraud
Browse files

media: update the resolution from decoder to receive_thread if change

Gitlab: #447

Change-Id: I249fb7034a12f117298187b7b42977760be3ef83
parent 2615b4fc
No related branches found
No related tags found
No related merge requests found
...@@ -532,6 +532,8 @@ MediaDecoder::prepareDecoderContext() ...@@ -532,6 +532,8 @@ MediaDecoder::prepareDecoderContext()
return -1; return -1;
} }
avcodec_parameters_to_context(decoderCtx_, avStream_->codecpar); avcodec_parameters_to_context(decoderCtx_, avStream_->codecpar);
width_ = decoderCtx_->width;
height_ = decoderCtx_->height;
decoderCtx_->framerate = avStream_->avg_frame_rate; decoderCtx_->framerate = avStream_->avg_frame_rate;
if (avStream_->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) { if (avStream_->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) {
if (decoderCtx_->framerate.num == 0 || decoderCtx_->framerate.den == 0) if (decoderCtx_->framerate.num == 0 || decoderCtx_->framerate.den == 0)
...@@ -579,6 +581,18 @@ MediaDecoder::decode(AVPacket& packet) ...@@ -579,6 +581,18 @@ MediaDecoder::decode(AVPacket& packet)
: std::static_pointer_cast<MediaFrame>(std::make_shared<AudioFrame>()); : std::static_pointer_cast<MediaFrame>(std::make_shared<AudioFrame>());
auto frame = f->pointer(); auto frame = f->pointer();
ret = avcodec_receive_frame(decoderCtx_, frame); ret = avcodec_receive_frame(decoderCtx_, frame);
if (resolutionChangedCallback_) {
if (decoderCtx_->width != width_ or decoderCtx_->height != height_) {
JAMI_DBG("Resolution changed from %dx%d to %dx%d",
width_,
height_,
decoderCtx_->width,
decoderCtx_->height);
width_ = decoderCtx_->width;
height_ = decoderCtx_->height;
resolutionChangedCallback_(width_, height_);
}
}
if (ret < 0 && ret != AVERROR(EAGAIN) && ret != AVERROR_EOF) { if (ret < 0 && ret != AVERROR(EAGAIN) && ret != AVERROR_EOF) {
return DecodeStatus::DecodeError; return DecodeStatus::DecodeError;
} }
......
...@@ -191,6 +191,8 @@ public: ...@@ -191,6 +191,8 @@ public:
MediaStream getStream(std::string name = "") const; MediaStream getStream(std::string name = "") const;
void setResolutionChangedCallback(std::function<void(int, int)> cb) { resolutionChangedCallback_ = std::move(cb); }
private: private:
NON_COPYABLE(MediaDecoder); NON_COPYABLE(MediaDecoder);
...@@ -223,6 +225,10 @@ private: ...@@ -223,6 +225,10 @@ private:
int prepareDecoderContext(); int prepareDecoderContext();
int64_t seekTime_ = -1; int64_t seekTime_ = -1;
void resetSeekTime() { seekTime_ = -1; } void resetSeekTime() { seekTime_ = -1; }
std::function<void(int, int)> resolutionChangedCallback_;
int width_;
int height_;
protected: protected:
AVDictionary* options_ = nullptr; AVDictionary* options_ = nullptr;
......
...@@ -82,6 +82,10 @@ VideoReceiveThread::setup() ...@@ -82,6 +82,10 @@ VideoReceiveThread::setup()
av_buffer_ref(displayMatrix.get())); av_buffer_ref(displayMatrix.get()));
publishFrame(std::static_pointer_cast<VideoFrame>(frame)); publishFrame(std::static_pointer_cast<VideoFrame>(frame));
})); }));
videoDecoder_->setResolutionChangedCallback([this] (int width, int height){
dstWidth_ = width;
dstHeight_ = height;
});
dstWidth_ = args_.width; dstWidth_ = args_.width;
dstHeight_ = args_.height; dstHeight_ = args_.height;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment