OSVR Framework (Internal Development Docs)  0.6-1962-g59773924
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
MediaSampleExchange.cpp
Go to the documentation of this file.
1 
11 // Copyright 2015 Sensics, Inc.
12 //
13 // Licensed under the Apache License, Version 2.0 (the "License");
14 // you may not use this file except in compliance with the License.
15 // You may obtain a copy of the License at
16 //
17 // http://www.apache.org/licenses/LICENSE-2.0
18 //
19 // Unless required by applicable law or agreed to in writing, software
20 // distributed under the License is distributed on an "AS IS" BASIS,
21 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
22 // See the License for the specific language governing permissions and
23 // limitations under the License.
24 
25 // Internal Includes
26 #include "MediaSampleExchange.h"
27 #include "SignalEvent.h"
28 
29 // Library/third-party includes
30 #include <boost/assert.hpp>
31 
32 // Standard includes
33 // - none
34 
36  SignalEvent produced;
37  SignalEvent consumed;
38 };
39 MediaSampleExchange::MediaSampleExchange()
40  : impl_(new MediaSampleExchange::Impl) {}
41 
42 MediaSampleExchange::~MediaSampleExchange() {
43  // Required for unique_ptr pimpl - see http://herbsutter.com/gotw/_100/
44 }
45 
47  IMediaSample *sample, osvr::util::time::TimeValue const &timestamp) {
48  BOOST_ASSERT_MSG(
49  sample != nullptr,
50  "Should not be signalling that there is a null sample available!");
51  BOOST_ASSERT_MSG(sample_ == nullptr,
52  "Sample should be consumed before the next one produced!");
53  sample_ = sample;
54  timestamp_ = timestamp;
55  impl_->produced.set();
56 }
57 
58 void MediaSampleExchange::signalSampleProduced(IMediaSample *sample) {
60 }
61 
62 bool MediaSampleExchange::waitForSample(std::chrono::milliseconds timeout) {
63  return impl_->produced.wait(timeout.count());
64 }
65 
66 void MediaSampleExchange::signalSampleConsumed() {
67  BOOST_ASSERT_MSG(sample_ != nullptr,
68  "Sample pointer should not be null when consumed!");
69  sample_ = nullptr;
70  impl_->consumed.set();
71 }
72 
74  std::chrono::milliseconds timeout) {
75  BOOST_ASSERT_MSG(
76  sample_ != nullptr,
77  "Sample pointer should not be null when waiting for consumer!");
78  return impl_->consumed.wait(timeout.count());
79 }
bool waitForSampleConsumed(std::chrono::milliseconds timeout)
void signalSampleProduced(IMediaSample *sample, osvr::util::time::TimeValue const &timestamp)
void getNow(TimeValue &tv)
Set the given TimeValue to the current time.
Definition: TimeValue.h:51
bool waitForSample(std::chrono::milliseconds timeout)
Standardized, portable parallel to struct timeval for representing both absolute times and time inter...
Definition: TimeValueC.h:81