Commit 334ddd8a authored by Tristan Matthews's avatar Tristan Matthews
Browse files

* #17558: video: shm buffer filling callback should be a pure virtual method

This way VideoSendThread will be able to implement it and we avoid the
callback hackery we had before.
parent 0f652d92
......@@ -10,7 +10,7 @@ libvideo_la_SOURCES = libav_utils.cpp libav_utils.h video_rtp_session.cpp \
video_v4l2_list.cpp video_v4l2.h video_v4l2_list.h \
video_preferences.h video_preferences.cpp \
packet_handle.h packet_handle.cpp check.h shm_header.h \
shm_sink.cpp shm_sink.h
shm_sink.cpp shm_sink.h video_provider.h
libvideo_la_LIBADD = @LIBAVCODEC_LIBS@ @LIBAVFORMAT_LIBS@ @LIBAVDEVICE_LIBS@ @LIBSWSCALE_LIBS@ @LIBAVUTIL_LIBS@ @CCRTP_LIBS@ @UDEV_LIBS@
......
......@@ -40,6 +40,7 @@
#include "shm_sink.h"
#include "shm_header.h"
#include "logger.h"
#include "video_provider.h"
#include <sys/mman.h>
#include <fcntl.h>
#include <cstdio>
......@@ -189,8 +190,7 @@ void SHMSink::render(const std::vector<unsigned char> &data)
shm_unlock();
}
// Note: this doesn't depend on VideoReceiveThread's implementation since it's forward declared.
void SHMSink::render_callback(sfl_video::VideoReceiveThread * const th, const Callback &callback, size_t bytes)
void SHMSink::render_callback(sfl_video::VideoProvider &provider, size_t bytes)
{
shm_lock();
......@@ -199,7 +199,7 @@ void SHMSink::render_callback(sfl_video::VideoReceiveThread * const th, const Ca
return;
}
callback(th, static_cast<void*>(shm_area_->data));
provider.fillBuffer(static_cast<void*>(shm_area_->data));
shm_area_->buffer_size = bytes;
shm_area_->buffer_gen++;
sem_post(&shm_area_->notification);
......
......@@ -36,21 +36,15 @@
#ifndef SHM_SINK_H_
#define SHM_SINK_H_
#include <semaphore.h>
#include <string>
#include <vector>
#include <tr1/functional>
#include "noncopyable.h"
class SHMHeader;
namespace sfl_video {
class VideoReceiveThread;
class VideoProvider;
}
// A VideoReceiveThread member function handle, where the member function
// takes a (void *) as an argument
typedef std::tr1::function<void (sfl_video::VideoReceiveThread * const, void *)> Callback;
class SHMSink {
public:
SHMSink(const std::string &shm_name = "");
......@@ -63,7 +57,7 @@ class SHMSink {
bool resize_area(size_t desired_length);
void render(const std::vector<unsigned char> &data);
void render_callback(sfl_video::VideoReceiveThread * const th, const Callback &callback, size_t bytes);
void render_callback(sfl_video::VideoProvider &provider, size_t bytes);
private:
NON_COPYABLE(SHMSink);
......
/*
* Copyright (C) 2012 Savoir-Faire Linux Inc.
* Author: Tristan Matthews <tristan.matthews@savoirfairelinux.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Additional permission under GNU GPL version 3 section 7:
*
* If you modify this program, or any covered work, by linking or
* combining it with the OpenSSL project's OpenSSL library (or a
* modified version of that library), containing parts covered by the
* terms of the OpenSSL or SSLeay licenses, Savoir-Faire Linux Inc.
* grants you additional permission to convey the resulting work.
* Corresponding Source for a non-source form of such a combination
* shall include the source code for the parts of OpenSSL used as well
* as that of the covered work.
*/
#ifndef VIDEO_PROVIDER_H_
#define VIDEO_PROVIDER_H_
namespace sfl_video {
class VideoProvider {
public:
virtual void fillBuffer(void *data) = 0;
virtual ~VideoProvider() {}
};
}
#endif // VIDEO_PROVIDER_H_
......@@ -255,7 +255,7 @@ void *VideoReceiveThread::runCallback(void *data)
}
/// Copies and scales our rendered frame to the buffer pointed to by data
void VideoReceiveThread::fill_buffer(void *data)
void VideoReceiveThread::fillBuffer(void *data)
{
avpicture_fill(reinterpret_cast<AVPicture *>(scaledPicture_),
static_cast<uint8_t *>(data),
......@@ -347,10 +347,9 @@ bool VideoReceiveThread::decodeFrame()
void VideoReceiveThread::renderFrame()
{
const Callback cb(&VideoReceiveThread::fill_buffer);
// we want our rendering code to be called by the shm_sink,
// because it manages the shared memory synchronization
sink_.render_callback(this, cb, bufferSize_);
sink_.render_callback(*this, bufferSize_);
}
......
......@@ -39,6 +39,7 @@
#include <tr1/memory>
#include "shm_sink.h"
#include "noncopyable.h"
#include "video_provider.h"
extern "C" {
#include <libavformat/avformat.h>
......@@ -51,7 +52,7 @@ class AVFormatContext;
class AVFrame;
namespace sfl_video {
class VideoReceiveThread {
class VideoReceiveThread : public VideoProvider {
private:
NON_COPYABLE(VideoReceiveThread);
std::map<std::string, std::string> args_;
......@@ -84,7 +85,7 @@ class VideoReceiveThread {
void setup();
void openDecoder();
void createScalingContext();
void fill_buffer(void *data);
void fillBuffer(void *data);
static int interruptCb(void *ctx);
friend struct VideoRxContextHandle;
static void *runCallback(void *);
......
Supports Markdown
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