2
thread safe wrapper for output Stream
3
Copyright (C) 2000 Martin Vogt
5
This program is free software; you can redistribute it and/or modify
6
it under the terms of the GNU Library General Public License as published by
7
the Free Software Foundation.
9
For more information look at the file COPYRIGHT in this package
14
#include "threadSafeOutputStream.h"
17
ThreadSafeOutputStream::ThreadSafeOutputStream(OutputStream* output) {
18
threadQueueAudio=new ThreadQueue();
19
threadQueueVideo=new ThreadQueue();
24
ThreadSafeOutputStream::~ThreadSafeOutputStream() {
25
delete threadQueueAudio;
26
delete threadQueueVideo;
30
int ThreadSafeOutputStream::audioInit() {
32
threadQueueAudio->waitForExclusiveAccess();
33
back=output->audioInit();
34
threadQueueAudio->releaseExclusiveAccess();
39
int ThreadSafeOutputStream::audioSetup(int freq,int stereo,
40
int sign,int big,int sampleSize) {
42
threadQueueAudio->waitForExclusiveAccess();
43
back=output->audioSetup(freq,stereo,sign,big,sampleSize);
44
threadQueueAudio->releaseExclusiveAccess();
49
int ThreadSafeOutputStream::audioPlay(TimeStamp* start,
50
TimeStamp* end,char* buf, int len) {
52
threadQueueAudio->waitForExclusiveAccess();
53
back=output->audioPlay(start,end,buf,len);
54
threadQueueAudio->releaseExclusiveAccess();
58
void ThreadSafeOutputStream::audioFlush() {
59
threadQueueAudio->waitForExclusiveAccess();
61
threadQueueAudio->releaseExclusiveAccess();
65
void ThreadSafeOutputStream::audioClose() {
66
threadQueueAudio->waitForExclusiveAccess();
68
threadQueueAudio->releaseExclusiveAccess();
71
void ThreadSafeOutputStream::audioOpen() {
72
threadQueueAudio->waitForExclusiveAccess();
74
threadQueueAudio->releaseExclusiveAccess();
79
int ThreadSafeOutputStream::getPreferredDeliverSize() {
81
threadQueueAudio->waitForExclusiveAccess();
82
back=output->getPreferredDeliverSize();
83
threadQueueAudio->releaseExclusiveAccess();
87
int ThreadSafeOutputStream::videoInit() {
89
threadQueueVideo->waitForExclusiveAccess();
90
back=output->videoInit();
91
threadQueueVideo->releaseExclusiveAccess();
95
int ThreadSafeOutputStream::openWindow(int w, int h,const char* title) {
97
threadQueueVideo->waitForExclusiveAccess();
98
back=output->openWindow(w,h,title);
99
threadQueueVideo->releaseExclusiveAccess();
104
void ThreadSafeOutputStream::closeWindow() {
105
threadQueueVideo->waitForExclusiveAccess();
106
output->closeWindow();
107
threadQueueVideo->releaseExclusiveAccess();
110
void ThreadSafeOutputStream::flushWindow() {
111
threadQueueVideo->waitForExclusiveAccess();
112
output->flushWindow();
113
threadQueueVideo->releaseExclusiveAccess();
117
PictureArray* ThreadSafeOutputStream::lockPictureArray() {
119
threadQueueVideo->waitForExclusiveAccess();
120
back=output->lockPictureArray();
121
threadQueueVideo->releaseExclusiveAccess();
126
void ThreadSafeOutputStream::unlockPictureArray(PictureArray* array) {
127
threadQueueVideo->waitForExclusiveAccess();
128
output->unlockPictureArray(array);
129
threadQueueVideo->releaseExclusiveAccess();
133
int ThreadSafeOutputStream::getFrameusec() {
135
threadQueueVideo->waitForExclusiveAccess();
136
back=output->getFrameusec();
137
threadQueueVideo->releaseExclusiveAccess();
141
void ThreadSafeOutputStream::config(const char* key,
142
const char* value,void* user_data) {
144
threadQueueVideo->waitForExclusiveAccess();
145
threadQueueAudio->waitForExclusiveAccess();
146
output->config(key,value,user_data);
147
threadQueueVideo->releaseExclusiveAccess();
148
threadQueueAudio->releaseExclusiveAccess();