Panda3D
ffmpegAudioCursor.h
1 // Filename: ffmpegAudioCursor.h
2 // Created by: jyelon (01Aug2007)
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 FFMPEGAUDIOCURSOR_H
16 #define FFMPEGAUDIOCURSOR_H
17 
18 #include "pandabase.h"
19 
20 #include "movieAudioCursor.h"
21 #include "namable.h"
22 #include "texture.h"
23 #include "pointerTo.h"
24 #include "ffmpegVirtualFile.h"
25 
26 extern "C" {
27  #include "libavcodec/avcodec.h"
28 }
29 
30 class FfmpegAudio;
31 struct AVFormatContext;
32 struct AVCodecContext;
33 struct AVStream;
34 struct AVPacket;
35 
36 #ifdef HAVE_SWRESAMPLE
37 struct SwrContext;
38 #endif
39 
40 ////////////////////////////////////////////////////////////////////
41 // Class : FfmpegAudioCursor
42 // Description : A stream that generates a sequence of audio samples.
43 ////////////////////////////////////////////////////////////////////
44 class EXPCL_FFMPEG FfmpegAudioCursor : public MovieAudioCursor {
45  friend class FfmpegAudio;
46 
47 PUBLISHED:
49  virtual ~FfmpegAudioCursor();
50  virtual void seek(double offset);
51 
52 public:
53  virtual void read_samples(int n, PN_int16 *data);
54 
55 protected:
56  void fetch_packet();
57  bool reload_buffer();
58  void cleanup();
59  Filename _filename;
60  int _initial_dts;
61  AVPacket *_packet;
62  int _packet_size;
63  unsigned char *_packet_data;
64  AVFormatContext *_format_ctx;
65  AVCodecContext *_audio_ctx;
66  FfmpegVirtualFile _ffvfile;
67  int _audio_index;
68  double _audio_timebase;
69 
70  AVFrame *_frame;
71  PN_int16 *_buffer;
72  int _buffer_size;
73  PN_int16 *_buffer_alloc;
74  int _buffer_head;
75  int _buffer_tail;
76 
77 #ifdef HAVE_SWRESAMPLE
78  SwrContext *_resample_ctx;
79 #endif
80 
81 public:
82  static TypeHandle get_class_type() {
83  return _type_handle;
84  }
85  static void init_type() {
86  MovieAudioCursor::init_type();
87  register_type(_type_handle, "FfmpegAudioCursor",
88  MovieAudioCursor::get_class_type());
89  }
90  virtual TypeHandle get_type() const {
91  return get_class_type();
92  }
93  virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
94 
95 private:
96  static TypeHandle _type_handle;
97 };
98 
99 #include "ffmpegAudioCursor.I"
100 
101 #endif // FFMPEGAUDIOCURSOR_H
void read_samples(int n, Datagram *dg)
Read audio samples from the stream into a Datagram.
A stream that generates a sequence of audio samples.
Definition: ffmpegAudio.h:27
Enables ffmpeg to access panda's VFS.
A stream that generates a sequence of audio samples.
The name of a file, such as a texture file or an Egg file.
Definition: filename.h:44
A MovieAudio is actually any source that provides a sequence of audio samples.
TypeHandle is the identifier used to differentiate C++ class types.
Definition: typeHandle.h:85
virtual void seek(double offset)
Skips to the specified offset within the file.