Panda3D
movieVideoCursor.h
1 // Filename: movieVideoCursor.h
2 // Created by: jyelon (02Jul07)
3 //
4 ////////////////////////////////////////////////////////////////////
5 //
6 // PANDA 3D SOFTWARE
7 // Copyright (c) Carnegie Mellon University. All rights reserved.
8 //
9 // All use of this software is subject to the terms of the revised BSD
10 // license. You should have received a copy of this license along
11 // with this source code in a file named "LICENSE."
12 //
13 ////////////////////////////////////////////////////////////////////
14 
15 #ifndef MOVIEVIDEOCURSOR_H
16 #define MOVIEVIDEOCURSOR_H
17 
18 #include "pandabase.h"
19 #include "texture.h"
20 #include "pointerTo.h"
21 #include "memoryBase.h"
22 #include "pStatCollector.h"
23 #include "deletedChain.h"
24 #include "typedReferenceCount.h"
25 
26 class MovieVideo;
27 class FactoryParams;
28 class BamWriter;
29 class BamReader;
30 
31 ////////////////////////////////////////////////////////////////////
32 // Class : MovieVideoCursor
33 // Description : A MovieVideo is actually any source that provides
34 // a sequence of video frames. That could include an
35 // AVI file, a digital camera, or an internet TV station.
36 // A MovieVideoCursor is a handle that lets you read
37 // data sequentially from a MovieVideo.
38 //
39 // Thread safety: each individual MovieVideoCursor
40 // must be owned and accessed by a single thread.
41 // It is OK for two different threads to open
42 // the same file at the same time, as long as they
43 // use separate MovieVideoCursor objects.
44 ////////////////////////////////////////////////////////////////////
45 class EXPCL_PANDA_MOVIES MovieVideoCursor : public TypedWritableReferenceCount {
46 protected:
47  MovieVideoCursor(MovieVideo *src = NULL);
48 
49 PUBLISHED:
50  virtual ~MovieVideoCursor();
51  PT(MovieVideo) get_source() const;
52  INLINE int size_x() const;
53  INLINE int size_y() const;
54  INLINE int get_num_components() const;
55  INLINE double length() const;
56  INLINE bool can_seek() const;
57  INLINE bool can_seek_fast() const;
58  INLINE bool aborted() const;
59 
60  INLINE bool ready() const;
61  INLINE bool streaming() const;
62  void setup_texture(Texture *tex) const;
63 
64  virtual bool set_time(double timestamp, int loop_count);
65 
66  class EXPCL_PANDA_MOVIES Buffer : public TypedReferenceCount {
67  public:
68  ALLOC_DELETED_CHAIN(Buffer);
69  Buffer(size_t block_size);
70 
71  PUBLISHED:
72  virtual ~Buffer();
73 
74  virtual int compare_timestamp(const Buffer *other) const;
75  virtual double get_timestamp() const;
76 
77  public:
78  unsigned char *_block;
79  size_t _block_size;
80 
81  private:
82  DeletedBufferChain *_deleted_chain;
83 
84  public:
85  static TypeHandle get_class_type() {
86  return _type_handle;
87  }
88  static void init_type() {
89  TypedReferenceCount::init_type();
90  register_type(_type_handle, "MovieVideoCursor::Buffer",
91  TypedReferenceCount::get_class_type());
92  }
93  virtual TypeHandle get_type() const {
94  return get_class_type();
95  }
96  virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
97 
98  private:
99  static TypeHandle _type_handle;
100  };
101  virtual PT(Buffer) fetch_buffer();
102 
103  virtual void apply_to_texture(const Buffer *buffer, Texture *t, int page);
104  virtual void apply_to_texture_rgb(const Buffer *buffer, Texture *t, int page);
105  virtual void apply_to_texture_alpha(const Buffer *buffer, Texture *t, int page, int alpha_src);
106 
107 protected:
108  Buffer *get_standard_buffer();
109  virtual PT(Buffer) make_new_buffer();
110 
111 protected:
112  PT(MovieVideo) _source;
113  int _size_x;
114  int _size_y;
115  int _num_components;
116  double _length;
117  bool _can_seek;
118  bool _can_seek_fast;
119  bool _aborted;
120  bool _streaming;
121  bool _ready;
122 
123  PT(Buffer) _standard_buffer;
124 
125  static PStatCollector _copy_pcollector;
126  static PStatCollector _copy_pcollector_ram;
127  static PStatCollector _copy_pcollector_copy;
128 
129 public:
130  virtual void write_datagram(BamWriter *manager, Datagram &dg);
131  virtual int complete_pointers(TypedWritable **plist, BamReader *manager);
132 
133 protected:
134  void fillin(DatagramIterator &scan, BamReader *manager);
135 
136 public:
137  static TypeHandle get_class_type() {
138  return _type_handle;
139  }
140  static void init_type() {
141  TypedWritableReferenceCount::init_type();
142  register_type(_type_handle, "MovieVideoCursor",
143  TypedWritableReferenceCount::get_class_type());
144  Buffer::init_type();
145  }
146  virtual TypeHandle get_type() const {
147  return get_class_type();
148  }
149  virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
150 
151 private:
152  static TypeHandle _type_handle;
153 };
154 
155 #include "movieVideoCursor.I"
156 #include "movieVideo.h"
157 
158 #endif
This is the fundamental interface for extracting binary objects from a Bam file, as generated by a Ba...
Definition: bamReader.h:122
Represents a texture object, which is typically a single 2-d image but may also represent a 1-d or 3-...
Definition: texture.h:75
Base class for objects that can be written to and read from Bam files.
Definition: typedWritable.h:37
A base class for things which need to inherit from both TypedObject and from ReferenceCount.
This is the fundamental interface for writing binary objects to a Bam file, to be extracted later by ...
Definition: bamWriter.h:73
This is our own Panda specialization on the default STL list.
Definition: plist.h:38
A lightweight class that represents a single element that may be timed and/or counted via stats...
A MovieVideo is actually any source that provides a sequence of video frames.
An instance of this class is passed to the Factory when requesting it to do its business and construc...
Definition: factoryParams.h:40
A base class for things which need to inherit from both TypedWritable and from ReferenceCount.
A MovieVideo is actually any source that provides a sequence of video frames.
Definition: movieVideo.h:42
A class to retrieve the individual data elements previously stored in a Datagram. ...
TypeHandle is the identifier used to differentiate C++ class types.
Definition: typeHandle.h:85
An ordered list of data elements, formatted in memory for transmission over a socket or writing to a ...
Definition: datagram.h:43
This template class can be used to provide faster allocation/deallocation for many Panda objects...