Commit 84f878d9 authored by Guillaume Roguez's avatar Guillaume Roguez Committed by Edric Milaret

cleanup video_base API

This patchset changes Observable::notify and Observer::update API
to remove the reference data attribute. This was uneeded into our context,
aka used with smart pointers.

Also fix coding rules and missing override keywords to overloaded virtual
methods.

Tuleap: #240
Change-Id: I068b44cb526718d4cbae34b9d4d51871294bcf3e
parent ae1e063d
......@@ -44,12 +44,6 @@ class AVCodec;
namespace ring {
#ifdef RING_VIDEO
namespace video {
class VideoPacket;
} // namespace ring::video
#endif // RING_VIDEO
class AudioFrame;
class AudioFormat;
class RingBuffer;
......
......@@ -309,9 +309,9 @@ SinkClient::SinkClient(const std::string& id, bool mixer)
void
SinkClient::update(Observable<std::shared_ptr<VideoFrame>>* /*obs*/,
std::shared_ptr<VideoFrame>& frame_p)
std::shared_ptr<VideoFrame> frame_p)
{
auto f = frame_p; // keep a local reference during rendering
auto& f = *frame_p;
#ifdef DEBUG_FPS
auto currentTime = std::chrono::system_clock::now();
......@@ -325,13 +325,14 @@ SinkClient::update(Observable<std::shared_ptr<VideoFrame>>* /*obs*/,
#endif
#if HAVE_SHM
shm_->renderFrame(*f.get());
shm_->renderFrame(f);
#endif
if (target_.pull) {
VideoFrame dst;
const int width = f->width();
const int height = f->height();
VideoScaler scaler;
const int width = f.width();
const int height = f.height();
#ifndef __APPLE__
const int format = VIDEO_PIXFMT_BGRA;
#else
......@@ -345,7 +346,7 @@ SinkClient::update(Observable<std::shared_ptr<VideoFrame>>* /*obs*/,
buffer_ptr->width = width;
buffer_ptr->height = height;
dst.setFromMemory(buffer_ptr->ptr, format, width, height);
scaler_->scale(*f, dst);
scaler_->scale(f, dst);
target_.push(std::move(buffer_ptr));
}
}
......
......@@ -54,7 +54,7 @@ class SinkClient : public VideoFramePassiveReader
// as VideoFramePassiveReader
void update(Observable<std::shared_ptr<ring::VideoFrame>>*,
std::shared_ptr<ring::VideoFrame>&);
std::shared_ptr<ring::VideoFrame>) override;
bool start() noexcept;
bool stop() noexcept;
......
......@@ -62,48 +62,48 @@ template <typename T> class Observable;
template <typename T>
class Observable
{
public:
Observable() : observers_(), mutex_() {}
virtual ~Observable() {
std::lock_guard<std::mutex> lk(mutex_);
for (auto &o : observers_)
o->detached(this);
};
bool attach(Observer<T>* o) {
std::lock_guard<std::mutex> lk(mutex_);
if (o and observers_.insert(o).second) {
o->attached(this);
return true;
}
return false;
public:
Observable() : observers_(), mutex_() {}
virtual ~Observable() {
std::lock_guard<std::mutex> lk(mutex_);
for (auto& o : observers_)
o->detached(this);
};
bool attach(Observer<T>* o) {
std::lock_guard<std::mutex> lk(mutex_);
if (o and observers_.insert(o).second) {
o->attached(this);
return true;
}
bool detach(Observer<T>* o) {
std::lock_guard<std::mutex> lk(mutex_);
if (o and observers_.erase(o)) {
o->detached(this);
return true;
}
return false;
return false;
}
bool detach(Observer<T>* o) {
std::lock_guard<std::mutex> lk(mutex_);
if (o and observers_.erase(o)) {
o->detached(this);
return true;
}
return false;
}
void notify(T& data) {
std::lock_guard<std::mutex> lk(mutex_);
for (auto observer : observers_)
observer->update(this, data);
}
void notify(T data) {
std::lock_guard<std::mutex> lk(mutex_);
for (auto observer : observers_)
observer->update(this, data);
}
int getObserversCount() {
std::lock_guard<std::mutex> lk(mutex_);
return observers_.size();
}
int getObserversCount() {
std::lock_guard<std::mutex> lk(mutex_);
return observers_.size();
}
private:
NON_COPYABLE(Observable<T>);
private:
NON_COPYABLE(Observable<T>);
std::set<Observer<T>*> observers_;
std::mutex mutex_; // lock observers_
std::set<Observer<T>*> observers_;
std::mutex mutex_; // lock observers_
};
/*=== Observer =============================================================*/
......@@ -113,7 +113,7 @@ class Observer
{
public:
virtual ~Observer() {};
virtual void update(Observable<T>*, T&) = 0;
virtual void update(Observable<T>*, T) = 0;
virtual void attached(Observable<T>*) {};
virtual void detached(Observable<T>*) {};
};
......
......@@ -101,7 +101,7 @@ VideoMixer::detached(Observable<std::shared_ptr<VideoFrame>>* ob)
void
VideoMixer::update(Observable<std::shared_ptr<VideoFrame>>* ob,
std::shared_ptr<VideoFrame>& frame_p)
std::shared_ptr<VideoFrame> frame_p)
{
auto lock(rwMutex_.read());
......@@ -111,7 +111,7 @@ VideoMixer::update(Observable<std::shared_ptr<VideoFrame>>* ob,
x->update_frame.reset(new VideoFrame);
else
x->update_frame->reset();
*x->update_frame = *frame_p;
*x->update_frame = *frame_p; // copy frame content, it will be destroyed after return
x->atomic_swap_render(x->update_frame);
return;
}
......
......@@ -44,14 +44,14 @@ public:
void setDimensions(int width, int height);
int getWidth() const;
int getHeight() const;
int getPixelFormat() const;
int getWidth() const override;
int getHeight() const override;
int getPixelFormat() const override;
// as VideoFramePassiveReader
void update(Observable<std::shared_ptr<VideoFrame>>* ob, std::shared_ptr<VideoFrame>& v);
void attached(Observable<std::shared_ptr<VideoFrame>>* ob);
void detached(Observable<std::shared_ptr<VideoFrame>>* ob);
void update(Observable<std::shared_ptr<VideoFrame>>* ob, std::shared_ptr<VideoFrame> v) override;
void attached(Observable<std::shared_ptr<VideoFrame>>* ob) override;
void detached(Observable<std::shared_ptr<VideoFrame>>* ob) override;
private:
NON_COPYABLE(VideoMixer);
......
......@@ -70,8 +70,8 @@ VideoSender::encodeAndSendVideo(VideoFrame& input_frame)
}
void
VideoSender::update(Observable<std::shared_ptr<VideoFrame> >* /*obs*/,
std::shared_ptr<VideoFrame> & frame_p)
VideoSender::update(Observable<std::shared_ptr<VideoFrame>>* /*obs*/,
std::shared_ptr<VideoFrame> frame_p)
{
encodeAndSendVideo(*frame_p);
}
......
......@@ -53,8 +53,8 @@ public:
void forceKeyFrame();
// as VideoFramePassiveReader
void update(Observable<std::shared_ptr<VideoFrame> >* obs,
std::shared_ptr<VideoFrame> &);
void update(Observable<std::shared_ptr<VideoFrame>>* obs,
std::shared_ptr<VideoFrame> frame_p) override;
void setMuted(bool isMuted);
uint16_t getLastSeqValue();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment