Subversion Repositories shark

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
2 pj 1
/*
2
 * Copyright (c) 1994 by Gregory P. Ward.
3
 * All rights reserved.
4
 *
5
 * This file is part of the MNI front end of the Berkeley MPEG decoder.
6
 *
7
 * Permission to use, copy, modify, and distribute this software and its
8
 * documentation for any purpose, without fee, and without written agreement is
9
 * hereby granted, provided that the above copyright notice and the following
10
 * two paragraphs appear in all copies of this software.
11
 *
12
 * IN NO EVENT SHALL THE AUTHOR BE LIABLE TO ANY PARTY FOR DIRECT,
13
 * INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT
14
 * OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE
15
 * UNIVERSITY OF CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF
16
 * SUCH DAMAGE.
17
 *
18
 * THE AUTHOR SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT
19
 * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
20
 * FITNESS FOR A PARTICULAR PURPOSE.  THE SOFTWARE PROVIDED HEREUNDER
21
 * IS ON AN "AS IS" BASIS, AND THE AUTHOR HAS NO OBLIGATION TO PROVIDE
22
 * MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.  
23
 */
24
/*
25
 * Portions of this software Copyright (c) 1995 Brown University.
26
 * All rights reserved.
27
 *
28
 * Permission to use, copy, modify, and distribute this software and its
29
 * documentation for any purpose, without fee, and without written agreement
30
 * is hereby granted, provided that the above copyright notice and the
31
 * following two paragraphs appear in all copies of this software.
32
 *
33
 * IN NO EVENT SHALL BROWN UNIVERSITY BE LIABLE TO ANY PARTY FOR DIRECT,
34
 * INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT
35
 * OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF BROWN
36
 * UNIVERSITY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
37
 *
38
 * BROWN UNIVERSITY SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT
39
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
40
 * PARTICULAR PURPOSE.  THE SOFTWARE PROVIDED HEREUNDER IS ON AN "AS IS"
41
 * BASIS, AND BROWN UNIVERSITY HAS NO OBLIGATION TO PROVIDE MAINTENANCE,
42
 * SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
43
 */
44
 
45
/*
46
 *
47
 * Original C version by Greg Ward <greg@pet.mni.mcgill.ca>,
48
 * reentrant C++ version by Loring Holden <lsh@cs.brown.edu>
49
 *
50
 * All functions that have an "MNI Header" are rewritten from the original
51
 * MNI C function
52
 *
53
 */
54
 
55
#include "ANIMbase.H"
56
 
57
#ifndef NOTHREADS
58
THREADmp_manager *ANIMbase::mp_man=NULL;
59
#endif
60
 
61
//
62
//Constructor
63
//
64
//
65
ANIMbase::ANIMbase()
66
  : threadNumber(-1),
67
    moreFrames(FALSE),
68
#ifndef NOTHREADS
69
    MultiThreaded(FALSE),
70
#endif
71
    fileName(NULL),
72
    buffering(FALSE),
73
    allBuffered(FALSE),
74
    frameBuffer(NULL),
75
    filePtr(NULL),
76
    frames(0)
77
{
78
}
79
 
80
//
81
//Copy constructor
82
//Copies settings from MultiThreading and buffering, and starts
83
//the same movie from the beginning
84
//
85
ANIMbase::ANIMbase(const ANIMbase& rhs)
86
  : threadNumber(-1),
87
    moreFrames(FALSE),
88
#ifndef NOTHREADS
89
    MultiThreaded(rhs.MultiThreaded),
90
#endif
91
    fileName(NULL),
92
    buffering(rhs.buffering),
93
    allBuffered(FALSE),
94
    frameBuffer(NULL),
95
    filePtr(NULL),
96
    frames(0)
97
{
98
}
99
 
100
 
101
// Destructor
102
/* ----------------------------- MNI Header -----------------------------------
103
@NAME       : CloseMPEG
104
@INPUT      : (none)
105
@OUTPUT     : (none)
106
@RETURNS    : (void)
107
@DESCRIPTION: Frees up some of the memory allocated by OpenMPEG() (some
108
              is not freed because the Berkeley code doesn't take into
109
              account the fact that somebody might want to, say, free
110
              up the memory it allocates... someday, I'll probably have
111
              to hack into it to fix that, but not today thanks.)
112
@METHOD     :
113
@GLOBALS    : lum_values
114
              cr_values
115
              cb_values
116
@CALLS      : DestroyVidStream
117
@CREATED    : 94/6/27, Greg Ward
118
@MODIFIED   : 95/10, Loring Holden (made reentrant and ported to C++)
119
---------------------------------------------------------------------------- */
120
ANIMbase::~ANIMbase()
121
{
122
//   newMovie(NULL);  //Like we are playing a new movie, but no new
123
//                  //allocation
124
#ifndef NOTHREADS
125
   MultiThread(FALSE);
126
#endif
127
 
128
}
129
 
130
//
131
// Access to private member MultiThreaded for the masses
132
// (Deals with starting or stopping MultiThreading)
133
//
134
#ifndef NOTHREADS
135
void
136
ANIMbase::MultiThread(Boolean whether) {
137
        if (whether==MultiThreaded) return;
138
 
139
        if (whether)  {
140
            //We should only do multi-threading if we have a routine to run
141
            //or we haven't buffered the movie yet
142
            if ((thread_routine!=NULL) && !allBuffered)  {
143
               if (mp_man==NULL) mp_man=new THREADmp_manager(1);
144
               threadNumber=mp_man->deqThread();
145
               // If we haven't called open() then don't start process
146
               if (moreFrames)
147
                 mp_man->processor(threadNumber)->
148
                  start_execute(thread_routine,this,NULL);
149
            } else return;
150
        } else {
151
           whether=FALSE;
152
           if (mp_man->processor(threadNumber)->running) {
153
              mp_man->processor(threadNumber)->wait_for_done();
154
           }
155
           mp_man->enqThread(threadNumber);
156
           threadNumber=-1;
157
        }
158
        MultiThreaded=whether;
159
}
160
#endif
161
 
162
//
163
// Access to private member buffering for the masses
164
// (allocates or deallocates buffer)
165
//
166
void
167
ANIMbase::Buffer(Boolean whether, Boolean compress) {
168
        if (whether==(buffering || allBuffered))  return;
169
        if (whether && !allBuffered && moreFrames) {
170
           int bytesSave=4;
171
           buffering=TRUE;
172
           allBuffered=FALSE;
173
           // create buffer to hold the frames
174
           if (compress) bytesSave=3;
175
           frameBuffer=new BUFFER(Size,4,bytesSave);
176
        }
177
        if (!whether) {
178
           buffering=allBuffered=FALSE;
179
           // delete buffer
180
           delete frameBuffer;
181
           frameBuffer=NULL;
182
        }
183
}