Panda3D
ffmpegAudioCursor.h
Go to the documentation of this file.
1 /**
2  * PANDA 3D SOFTWARE
3  * Copyright (c) Carnegie Mellon University. All rights reserved.
4  *
5  * All use of this software is subject to the terms of the revised BSD
6  * license. You should have received a copy of this license along
7  * with this source code in a file named "LICENSE."
8  *
9  * @file ffmpegAudioCursor.h
10  * @author jyelon
11  * @date 2007-08-01
12  */
13 
14 #ifndef FFMPEGAUDIOCURSOR_H
15 #define FFMPEGAUDIOCURSOR_H
16 
17 #include "pandabase.h"
18 
19 #include "movieAudioCursor.h"
20 #include "namable.h"
21 #include "texture.h"
22 #include "pointerTo.h"
23 #include "ffmpegVirtualFile.h"
24 
25 extern "C" {
26  #include <libavcodec/avcodec.h>
27 }
28 
29 class FfmpegAudio;
30 struct AVFormatContext;
31 struct AVCodecContext;
32 struct AVStream;
33 struct AVPacket;
34 struct SwrContext;
35 
36 /**
37  * A stream that generates a sequence of audio samples.
38  */
39 class EXPCL_FFMPEG FfmpegAudioCursor : public MovieAudioCursor {
40  friend class FfmpegAudio;
41 
42 PUBLISHED:
44  virtual ~FfmpegAudioCursor();
45  virtual void seek(double offset);
46 
47 public:
48  virtual void read_samples(int n, int16_t *data);
49 
50 protected:
51  void fetch_packet();
52  bool reload_buffer();
53  void cleanup();
54  Filename _filename;
55  int _initial_dts;
56  AVPacket *_packet;
57  int _packet_size;
58  unsigned char *_packet_data;
59  AVFormatContext *_format_ctx;
60  AVCodecContext *_audio_ctx;
61  FfmpegVirtualFile _ffvfile;
62  int _audio_index;
63  double _audio_timebase;
64 
65  AVFrame *_frame;
66  int16_t *_buffer;
67  int _buffer_size;
68  int16_t *_buffer_alloc;
69  int _buffer_head;
70  int _buffer_tail;
71 
72  SwrContext *_resample_ctx;
73 
74 public:
75  static TypeHandle get_class_type() {
76  return _type_handle;
77  }
78  static void init_type() {
79  MovieAudioCursor::init_type();
80  register_type(_type_handle, "FfmpegAudioCursor",
81  MovieAudioCursor::get_class_type());
82  }
83  virtual TypeHandle get_type() const {
84  return get_class_type();
85  }
86  virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
87 
88 private:
89  static TypeHandle _type_handle;
90 };
91 
92 #include "ffmpegAudioCursor.I"
93 
94 #endif // FFMPEGAUDIOCURSOR_H
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
void read_samples(int n, Datagram *dg)
Read audio samples from the stream into a Datagram.
void register_type(TypeHandle &type_handle, const std::string &name)
This inline function is just a convenient way to call TypeRegistry::register_type(),...
Definition: register_type.I:22
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
A stream that generates a sequence of audio samples.
Definition: ffmpegAudio.h:25
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
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:39
A MovieAudio is actually any source that provides a sequence of audio samples.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
TypeHandle is the identifier used to differentiate C++ class types.
Definition: typeHandle.h:81
virtual void seek(double offset)
Skips to the specified offset within the file.