mirror of
https://github.com/panda3d/panda3d.git
synced 2025-10-18 12:43:44 -04:00
A few bugfixes
This commit is contained in:
parent
a89589033b
commit
0134ba96e3
@ -30,9 +30,9 @@ TypeHandle FfmpegAudio::_type_handle;
|
||||
////////////////////////////////////////////////////////////////////
|
||||
FfmpegAudio::
|
||||
FfmpegAudio(const Filename &name) :
|
||||
MovieAudio(name),
|
||||
_specified_filename(name)
|
||||
MovieAudio(name)
|
||||
{
|
||||
_filename = name;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
@ -51,7 +51,13 @@ FfmpegAudio::
|
||||
////////////////////////////////////////////////////////////////////
|
||||
PT(MovieAudioCursor) FfmpegAudio::
|
||||
open() {
|
||||
return new FfmpegAudioCursor(this);
|
||||
PT(FfmpegAudioCursor) result = new FfmpegAudioCursor(this);
|
||||
if (result->_format_ctx == 0) {
|
||||
movies_cat.error() << "Could not open " << _filename << "\n";
|
||||
return NULL;
|
||||
} else {
|
||||
return (MovieAudioCursor*)(FfmpegAudioCursor*)result;
|
||||
}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
@ -36,7 +36,6 @@ PUBLISHED:
|
||||
virtual PT(MovieAudioCursor) open();
|
||||
|
||||
private:
|
||||
Filename _specified_filename;
|
||||
friend class FfmpegAudioCursor;
|
||||
|
||||
public:
|
||||
|
@ -30,9 +30,15 @@ TypeHandle FfmpegAudioCursor::_type_handle;
|
||||
// Description: xxx
|
||||
////////////////////////////////////////////////////////////////////
|
||||
FfmpegAudioCursor::
|
||||
FfmpegAudioCursor(PT(FfmpegAudio) src) :
|
||||
MovieAudioCursor((MovieAudio*)(FfmpegAudio*)src),
|
||||
_filename(src->_specified_filename)
|
||||
FfmpegAudioCursor(FfmpegAudio *src) :
|
||||
MovieAudioCursor(src),
|
||||
_filename(src->_filename),
|
||||
_packet(0),
|
||||
_packet_data(0),
|
||||
_format_ctx(0),
|
||||
_audio_ctx(0),
|
||||
_buffer(0),
|
||||
_buffer_alloc(0)
|
||||
{
|
||||
string url = "pandavfs:";
|
||||
url += _filename;
|
||||
@ -211,25 +217,36 @@ reload_buffer() {
|
||||
////////////////////////////////////////////////////////////////////
|
||||
void FfmpegAudioCursor::
|
||||
seek(double t) {
|
||||
movies_cat.error() << "Seek not implemented yet.\n";
|
||||
// PN_int64 target_ts = (PN_int64)(t / _audio_timebase);
|
||||
// if (target_ts < (PN_int64)(_initial_dts)) {
|
||||
// // Attempts to seek before the first packet will fail.
|
||||
// target_ts = _initial_dts;
|
||||
// }
|
||||
// if (av_seek_frame(_format_ctx, _audio_index, target_ts, AVSEEK_FLAG_BACKWARD) < 0) {
|
||||
// if (t >= _packet_time) {
|
||||
// return;
|
||||
// }
|
||||
// movies_cat.error() << "Seek failure. Shutting down movie.\n";
|
||||
// cleanup();
|
||||
// _packet_time = t;
|
||||
// return;
|
||||
// }
|
||||
// fetch_packet(t);
|
||||
// if (_packet_time > t) {
|
||||
// _packet_time = t;
|
||||
// }
|
||||
PN_int64 target_ts = (PN_int64)(t / _audio_timebase);
|
||||
if (target_ts < (PN_int64)(_initial_dts)) {
|
||||
// Attempts to seek before the first packet will fail.
|
||||
target_ts = _initial_dts;
|
||||
}
|
||||
if (av_seek_frame(_format_ctx, _audio_index, target_ts, AVSEEK_FLAG_BACKWARD) < 0) {
|
||||
movies_cat.error() << "Seek failure. Shutting down movie.\n";
|
||||
cleanup();
|
||||
return;
|
||||
}
|
||||
avcodec_close(_audio_ctx);
|
||||
AVCodec *pAudioCodec=avcodec_find_decoder(_audio_ctx->codec_id);
|
||||
if(pAudioCodec == 0) {
|
||||
cleanup();
|
||||
return;
|
||||
}
|
||||
if(avcodec_open(_audio_ctx, pAudioCodec)<0) {
|
||||
cleanup();
|
||||
return;
|
||||
}
|
||||
_buffer_head = 0;
|
||||
_buffer_tail = 0;
|
||||
fetch_packet();
|
||||
double ts = _packet->dts * _audio_timebase;
|
||||
if (t > ts) {
|
||||
int skip = (int)((t-ts) * _audio_rate);
|
||||
read_samples(skip, 0);
|
||||
}
|
||||
_last_seek = t;
|
||||
_samples_read = 0;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
@ -250,8 +267,10 @@ read_samples(int n, PN_int16 *data) {
|
||||
int available = _buffer_tail - _buffer_head;
|
||||
int ncopy = (desired > available) ? available : desired;
|
||||
if (ncopy) {
|
||||
memcpy(data, _buffer + _buffer_head, ncopy * 2);
|
||||
data += ncopy;
|
||||
if (data != 0) {
|
||||
memcpy(data, _buffer + _buffer_head, ncopy * 2);
|
||||
data += ncopy;
|
||||
}
|
||||
desired -= ncopy;
|
||||
_buffer_head += ncopy;
|
||||
}
|
||||
|
@ -35,9 +35,10 @@ struct AVPacket;
|
||||
// Description : A stream that generates a sequence of audio samples.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
class EXPCL_PANDA_MOVIES FfmpegAudioCursor : public MovieAudioCursor {
|
||||
friend class FfmpegAudio;
|
||||
|
||||
PUBLISHED:
|
||||
FfmpegAudioCursor(PT(FfmpegAudio) src);
|
||||
FfmpegAudioCursor(FfmpegAudio *src);
|
||||
virtual ~FfmpegAudioCursor();
|
||||
virtual void seek(double offset);
|
||||
|
||||
|
@ -30,9 +30,9 @@ TypeHandle FfmpegVideo::_type_handle;
|
||||
////////////////////////////////////////////////////////////////////
|
||||
FfmpegVideo::
|
||||
FfmpegVideo(const Filename &name) :
|
||||
MovieVideo(name),
|
||||
_specified_filename(name)
|
||||
MovieVideo(name)
|
||||
{
|
||||
_filename = name;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
@ -51,7 +51,13 @@ FfmpegVideo::
|
||||
////////////////////////////////////////////////////////////////////
|
||||
PT(MovieVideoCursor) FfmpegVideo::
|
||||
open() {
|
||||
return new FfmpegVideoCursor(this);
|
||||
PT(FfmpegVideoCursor) result = new FfmpegVideoCursor(this);
|
||||
if (result->_format_ctx == 0) {
|
||||
movies_cat.error() << "Could not open " << _filename << "\n";
|
||||
return NULL;
|
||||
} else {
|
||||
return (MovieVideoCursor*)(FfmpegVideoCursor*)result;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -36,7 +36,6 @@ class EXPCL_PANDA_MOVIES FfmpegVideo : public MovieVideo {
|
||||
virtual PT(MovieVideoCursor) open();
|
||||
|
||||
private:
|
||||
Filename _specified_filename;
|
||||
friend class FfmpegVideoCursor;
|
||||
|
||||
public:
|
||||
|
@ -41,14 +41,15 @@ TypeHandle FfmpegVideoCursor::_type_handle;
|
||||
// Description: xxx
|
||||
////////////////////////////////////////////////////////////////////
|
||||
FfmpegVideoCursor::
|
||||
FfmpegVideoCursor(PT(FfmpegVideo) src) :
|
||||
MovieVideoCursor((MovieVideo*)(FfmpegVideo*)src),
|
||||
_filename(src->_specified_filename),
|
||||
FfmpegVideoCursor(FfmpegVideo *src) :
|
||||
MovieVideoCursor(src),
|
||||
_filename(src->_filename),
|
||||
_format_ctx(0),
|
||||
_video_index(-1),
|
||||
_video_ctx(0),
|
||||
_frame(0),
|
||||
_frame_out(0),
|
||||
_packet(0),
|
||||
_min_fseek(3.0)
|
||||
{
|
||||
string url = "pandavfs:";
|
||||
@ -127,7 +128,15 @@ FfmpegVideoCursor::
|
||||
////////////////////////////////////////////////////////////////////
|
||||
void FfmpegVideoCursor::
|
||||
cleanup() {
|
||||
_frame_out->data[0] = 0;
|
||||
if (_frame) {
|
||||
av_free(_frame);
|
||||
_frame = 0;
|
||||
}
|
||||
if (_frame_out) {
|
||||
_frame_out->data[0] = 0;
|
||||
av_free(_frame_out);
|
||||
_frame_out = 0;
|
||||
}
|
||||
if (_packet) {
|
||||
if (_packet->data) {
|
||||
av_free_packet(_packet);
|
||||
@ -143,14 +152,6 @@ cleanup() {
|
||||
av_close_input_file(_format_ctx);
|
||||
_format_ctx = 0;
|
||||
}
|
||||
if (_frame) {
|
||||
av_free(_frame);
|
||||
_frame = 0;
|
||||
}
|
||||
if (_frame_out) {
|
||||
av_free(_frame_out);
|
||||
_frame_out = 0;
|
||||
}
|
||||
_video_ctx = 0;
|
||||
_video_index = -1;
|
||||
}
|
||||
@ -243,6 +244,16 @@ seek(double t) {
|
||||
_packet_time = t;
|
||||
return;
|
||||
}
|
||||
avcodec_close(_video_ctx);
|
||||
AVCodec *pVideoCodec=avcodec_find_decoder(_video_ctx->codec_id);
|
||||
if(pVideoCodec == 0) {
|
||||
cleanup();
|
||||
return;
|
||||
}
|
||||
if(avcodec_open(_video_ctx, pVideoCodec)<0) {
|
||||
cleanup();
|
||||
return;
|
||||
}
|
||||
fetch_packet(t);
|
||||
if (_packet_time > t) {
|
||||
_packet_time = t;
|
||||
|
@ -35,9 +35,10 @@ struct AVFrame;
|
||||
// Description :
|
||||
////////////////////////////////////////////////////////////////////
|
||||
class EXPCL_PANDA_MOVIES FfmpegVideoCursor : public MovieVideoCursor {
|
||||
friend class FfmpegVideo;
|
||||
|
||||
PUBLISHED:
|
||||
FfmpegVideoCursor(PT(FfmpegVideo) src);
|
||||
FfmpegVideoCursor(FfmpegVideo *src);
|
||||
virtual ~FfmpegVideoCursor();
|
||||
|
||||
public:
|
||||
|
@ -56,8 +56,8 @@ static color colormap[17] = {
|
||||
// Description: xxx
|
||||
////////////////////////////////////////////////////////////////////
|
||||
InkblotVideoCursor::
|
||||
InkblotVideoCursor(PT(InkblotVideo) src) :
|
||||
MovieVideoCursor((MovieVideo*)(InkblotVideo*)src)
|
||||
InkblotVideoCursor(InkblotVideo *src) :
|
||||
MovieVideoCursor(src)
|
||||
{
|
||||
_size_x = src->_specified_x;
|
||||
_size_y = src->_specified_y;
|
||||
|
@ -32,7 +32,7 @@
|
||||
class EXPCL_PANDA_MOVIES InkblotVideoCursor : public MovieVideoCursor {
|
||||
|
||||
PUBLISHED:
|
||||
InkblotVideoCursor(PT(InkblotVideo) src);
|
||||
InkblotVideoCursor(InkblotVideo *src);
|
||||
virtual ~InkblotVideoCursor();
|
||||
|
||||
public:
|
||||
|
@ -16,3 +16,15 @@
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: MovieAudio::get_filename
|
||||
// Access: Published
|
||||
// Description: Returns the movie's filename. A movie is not
|
||||
// guaranteed to have a filename, if not, then this
|
||||
// function returns a null filename.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
INLINE const Filename &MovieAudio::
|
||||
get_filename() const {
|
||||
return _filename;
|
||||
}
|
||||
|
||||
|
@ -23,8 +23,7 @@
|
||||
#include "namable.h"
|
||||
#include "pointerTo.h"
|
||||
#include "typedWritableReferenceCount.h"
|
||||
class MovieAudio;
|
||||
#include "movieAudioCursor.h"
|
||||
class MovieAudioCursor;
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Class : MovieAudio
|
||||
@ -40,13 +39,17 @@ class MovieAudio;
|
||||
////////////////////////////////////////////////////////////////////
|
||||
class EXPCL_PANDA_MOVIES MovieAudio : public TypedWritableReferenceCount, public Namable {
|
||||
|
||||
PUBLISHED:
|
||||
PUBLISHED:
|
||||
MovieAudio(const string &name = "Blank Audio");
|
||||
virtual ~MovieAudio();
|
||||
virtual PT(MovieAudioCursor) open();
|
||||
static PT(MovieAudio) get(const Filename &name);
|
||||
|
||||
public:
|
||||
INLINE const Filename &get_filename() const;
|
||||
|
||||
protected:
|
||||
Filename _filename;
|
||||
|
||||
public:
|
||||
static TypeHandle get_class_type() {
|
||||
return _type_handle;
|
||||
}
|
||||
@ -60,10 +63,11 @@ public:
|
||||
}
|
||||
virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
|
||||
|
||||
private:
|
||||
private:
|
||||
static TypeHandle _type_handle;
|
||||
};
|
||||
|
||||
#include "movieAudio.I"
|
||||
#include "movieAudioCursor.h"
|
||||
|
||||
#endif
|
||||
|
@ -29,7 +29,7 @@ TypeHandle MovieAudioCursor::_type_handle;
|
||||
// a subclass of this class.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
MovieAudioCursor::
|
||||
MovieAudioCursor(PT(MovieAudio) src) :
|
||||
MovieAudioCursor(MovieAudio *src) :
|
||||
_source(src),
|
||||
_audio_rate(8000),
|
||||
_audio_channels(1),
|
||||
|
@ -23,8 +23,7 @@
|
||||
#include "namable.h"
|
||||
#include "texture.h"
|
||||
#include "pointerTo.h"
|
||||
class MovieAudioCursor;
|
||||
#include "movieAudio.h"
|
||||
class MovieAudio;
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Class : MovieAudioCursor
|
||||
@ -43,7 +42,7 @@ class MovieAudioCursor;
|
||||
class EXPCL_PANDA_MOVIES MovieAudioCursor : public TypedWritableReferenceCount {
|
||||
|
||||
PUBLISHED:
|
||||
MovieAudioCursor(PT(MovieAudio) src);
|
||||
MovieAudioCursor(MovieAudio *src);
|
||||
virtual ~MovieAudioCursor();
|
||||
INLINE PT(MovieAudio) get_source() const;
|
||||
INLINE int audio_rate() const;
|
||||
@ -89,5 +88,6 @@ private:
|
||||
};
|
||||
|
||||
#include "movieAudioCursor.I"
|
||||
#include "movieAudio.h"
|
||||
|
||||
#endif
|
||||
|
@ -16,3 +16,14 @@
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: MovieVideo::get_filename
|
||||
// Access: Published
|
||||
// Description: Returns the movie's filename. A movie is not
|
||||
// guaranteed to have a filename, if not, then this
|
||||
// function returns a null filename.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
INLINE const Filename &MovieVideo::
|
||||
get_filename() const {
|
||||
return _filename;
|
||||
}
|
||||
|
@ -23,8 +23,7 @@
|
||||
#include "namable.h"
|
||||
#include "pointerTo.h"
|
||||
#include "typedWritableReferenceCount.h"
|
||||
class MovieVideo;
|
||||
#include "movieVideoCursor.h"
|
||||
class MovieVideoCursor;
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Class : MovieVideo
|
||||
@ -45,8 +44,12 @@ class EXPCL_PANDA_MOVIES MovieVideo : public TypedWritableReferenceCount, public
|
||||
virtual ~MovieVideo();
|
||||
virtual PT(MovieVideoCursor) open();
|
||||
static PT(MovieVideo) get(const Filename &name);
|
||||
INLINE const Filename &get_filename() const;
|
||||
|
||||
public:
|
||||
protected:
|
||||
Filename _filename;
|
||||
|
||||
public:
|
||||
static TypeHandle get_class_type() {
|
||||
return _type_handle;
|
||||
}
|
||||
@ -60,10 +63,11 @@ public:
|
||||
}
|
||||
virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
|
||||
|
||||
private:
|
||||
private:
|
||||
static TypeHandle _type_handle;
|
||||
};
|
||||
|
||||
#include "movieVideo.I"
|
||||
#include "movieVideoCursor.h"
|
||||
|
||||
#endif
|
||||
|
@ -30,7 +30,7 @@ TypeHandle MovieVideoCursor::_type_handle;
|
||||
// to construct a subclass of this class.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
MovieVideoCursor::
|
||||
MovieVideoCursor(PT(MovieVideo) src) :
|
||||
MovieVideoCursor(MovieVideo *src) :
|
||||
_source(src),
|
||||
_size_x(1),
|
||||
_size_y(1),
|
||||
@ -40,7 +40,8 @@ MovieVideoCursor(PT(MovieVideo) src) :
|
||||
_can_seek_fast(true),
|
||||
_aborted(false),
|
||||
_last_start(-1.0),
|
||||
_next_start(0.0)
|
||||
_next_start(0.0),
|
||||
_conversion_buffer(0)
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -22,8 +22,7 @@
|
||||
#include "pandabase.h"
|
||||
#include "texture.h"
|
||||
#include "pointerTo.h"
|
||||
class MovieVideoCursor;
|
||||
#include "movieVideo.h"
|
||||
class MovieVideo;
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Class : MovieVideoCursor
|
||||
@ -42,7 +41,7 @@ class MovieVideoCursor;
|
||||
class EXPCL_PANDA_MOVIES MovieVideoCursor : public TypedWritableReferenceCount {
|
||||
|
||||
PUBLISHED:
|
||||
MovieVideoCursor(PT(MovieVideo) src);
|
||||
MovieVideoCursor(MovieVideo *src);
|
||||
virtual ~MovieVideoCursor();
|
||||
PT(MovieVideo) get_source() const;
|
||||
INLINE int size_x() const;
|
||||
@ -97,5 +96,6 @@ private:
|
||||
};
|
||||
|
||||
#include "movieVideoCursor.I"
|
||||
#include "movieVideo.h"
|
||||
|
||||
#endif
|
||||
|
Loading…
x
Reference in New Issue
Block a user