Cosmetics
[rawv.git] / ivideo.cpp
blob91a487edacbe9716fe48d06cf945ac6fb7205b6f
1 /* rawv video source & sink interfaces, helpers
2 * Copyright (C) 2012 Kirill Smelkov <kirr@navytux.spb.ru>
4 * This library is free software: you can Use, Study, Modify and Redistribute
5 * it under the terms of the GNU Lesser General Public License version 2.1, or
6 * any later version. This library is distributed WITHOUT ANY WARRANTY. See
7 * COPYING.LIB file for full License terms.
8 */
10 #include "rawv.h"
12 namespace rawv {
15 IVideoSink::~IVideoSink()
18 IVideoSource::~IVideoSource()
23 VideoSource::VideoSource()
25 vs_sinkbuf = NULL;
28 VideoSource::~VideoSource()
32 void VideoSource::notify_v_subscribers(const Frame *f)
34 unsigned i;
36 for (i=0; i<v_subscribers.size(); ++i) {
37 IVideoSink *vs = v_subscribers[i];
39 /* sink which provided framebuffer should be notified last */
40 if (vs == vs_sinkbuf)
41 continue;
43 vs->v_on_frame(f);
46 if (vs_sinkbuf) {
47 vs_sinkbuf->v_on_frame(f);
48 vs_sinkbuf = NULL;
53 bool VideoSource::query_sink_framebuf(Frame *f)
55 IVideoSink *vs;
56 bool ok = false;
57 unsigned i;
59 if (vs_sinkbuf)
60 die("VideoSource->query_sink_framebuf(): sinkbuf was already queried");
63 for (i=0; i<v_subscribers.size(); ++i) {
64 vs = v_subscribers[i];
66 ok = vs->v_query_framebuf(f);
67 if (ok) {
68 vs_sinkbuf = vs;
69 break;
73 return ok;
77 void VideoSource::v_subscribe(IVideoSink *vs)
79 v_subscribers.push_back(vs);
83 void VideoSource::v_unsubscribe(IVideoSink *vs)
85 /* TODO handle unsubscribe of framebuf provider */
86 if (vs == vs_sinkbuf)
87 die("TODO VideoSource: handle vs_sinkbuf unsubscription");
89 for (vector<IVideoSink *>::iterator it=v_subscribers.begin(); it != v_subscribers.end();) {
90 if (vs == *it)
91 v_subscribers.erase(it);
92 else
93 ++it;
98 } // rawv::