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