fix printouts on 32bit
This commit is contained in:
parent
0865201e1e
commit
6e17bfefdd
|
@ -106,26 +106,25 @@ static int parse_key_value_pair(AVDictionary **pm, const char **buf,
|
|||
return ret;
|
||||
}
|
||||
int av_dict_parse_string(AVDictionary **pm, const char *str,
|
||||
const char *key_val_sep, const char *pairs_sep,
|
||||
int flags)
|
||||
{
|
||||
if (!str)
|
||||
return 0;
|
||||
|
||||
/* ignore STRDUP flags */
|
||||
flags &= ~(AV_DICT_DONT_STRDUP_KEY | AV_DICT_DONT_STRDUP_VAL);
|
||||
|
||||
while (*str) {
|
||||
int ret;
|
||||
if ( (ret = parse_key_value_pair(pm, &str, key_val_sep, pairs_sep, flags)) < 0)
|
||||
return ret;
|
||||
|
||||
if (*str)
|
||||
str++;
|
||||
}
|
||||
|
||||
return 0;
|
||||
const char *key_val_sep, const char *pairs_sep,
|
||||
int flags) {
|
||||
if (!str)
|
||||
return 0;
|
||||
|
||||
/* ignore STRDUP flags */
|
||||
flags &= ~(AV_DICT_DONT_STRDUP_KEY | AV_DICT_DONT_STRDUP_VAL);
|
||||
|
||||
while (*str) {
|
||||
int ret;
|
||||
if ( (ret = parse_key_value_pair(pm, &str, key_val_sep, pairs_sep, flags)) < 0)
|
||||
return ret;
|
||||
|
||||
if (*str)
|
||||
str++;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
#endif // HAVE_LIBAVUTIL
|
||||
|
||||
|
|
|
@ -27,8 +27,7 @@
|
|||
#include <errno.h>
|
||||
#include <sys/time.h>
|
||||
|
||||
struct timespec getTimeout( int secs )
|
||||
{
|
||||
struct timespec getTimeout( int secs ) {
|
||||
struct timespec timeout;
|
||||
struct timeval temp_timeout;
|
||||
gettimeofday( &temp_timeout, 0 );
|
||||
|
@ -37,65 +36,56 @@ struct timespec getTimeout( int secs )
|
|||
return( timeout );
|
||||
}
|
||||
|
||||
struct timespec getTimeout( double secs )
|
||||
{
|
||||
struct timespec getTimeout( double secs ) {
|
||||
struct timespec timeout;
|
||||
struct timeval temp_timeout;
|
||||
gettimeofday( &temp_timeout, 0 );
|
||||
timeout.tv_sec = temp_timeout.tv_sec + int(secs);
|
||||
timeout.tv_nsec = temp_timeout.tv_usec += (long int)(1000000000.0*(secs-int(secs)));
|
||||
if ( timeout.tv_nsec > 1000000000 )
|
||||
{
|
||||
if ( timeout.tv_nsec > 1000000000 ) {
|
||||
timeout.tv_sec += 1;
|
||||
timeout.tv_nsec -= 1000000000;
|
||||
}
|
||||
return( timeout );
|
||||
}
|
||||
|
||||
Mutex::Mutex()
|
||||
{
|
||||
Mutex::Mutex() {
|
||||
if ( pthread_mutex_init( &mMutex, NULL ) < 0 )
|
||||
throw ThreadException( stringtf( "Unable to create pthread mutex: %s", strerror(errno) ) );
|
||||
Fatal( "Unable to create pthread mutex: %s", strerror(errno) );
|
||||
}
|
||||
|
||||
Mutex::~Mutex()
|
||||
{
|
||||
Mutex::~Mutex() {
|
||||
if ( locked() )
|
||||
Warning( "Destroying mutex when locked" );
|
||||
if ( pthread_mutex_destroy( &mMutex ) < 0 )
|
||||
throw ThreadException( stringtf( "Unable to destroy pthread mutex: %s", strerror(errno) ) );
|
||||
Fatal( "Unable to destroy pthread mutex: %s", strerror(errno) );
|
||||
}
|
||||
|
||||
void Mutex::lock()
|
||||
{
|
||||
void Mutex::lock() {
|
||||
if ( pthread_mutex_lock( &mMutex ) < 0 )
|
||||
throw ThreadException( stringtf( "Unable to lock pthread mutex: %s", strerror(errno) ) );
|
||||
//Debug(3, "Lock");
|
||||
}
|
||||
|
||||
void Mutex::lock( int secs )
|
||||
{
|
||||
void Mutex::lock( int secs ) {
|
||||
struct timespec timeout = getTimeout( secs );
|
||||
if ( pthread_mutex_timedlock( &mMutex, &timeout ) < 0 )
|
||||
throw ThreadException( stringtf( "Unable to timedlock pthread mutex: %s", strerror(errno) ) );
|
||||
}
|
||||
|
||||
void Mutex::lock( double secs )
|
||||
{
|
||||
void Mutex::lock( double secs ) {
|
||||
struct timespec timeout = getTimeout( secs );
|
||||
if ( pthread_mutex_timedlock( &mMutex, &timeout ) < 0 )
|
||||
throw ThreadException( stringtf( "Unable to timedlock pthread mutex: %s", strerror(errno) ) );
|
||||
}
|
||||
|
||||
void Mutex::unlock()
|
||||
{
|
||||
void Mutex::unlock() {
|
||||
if ( pthread_mutex_unlock( &mMutex ) < 0 )
|
||||
throw ThreadException( stringtf( "Unable to unlock pthread mutex: %s", strerror(errno) ) );
|
||||
//Debug(3, "unLock");
|
||||
}
|
||||
|
||||
bool Mutex::locked()
|
||||
{
|
||||
bool Mutex::locked() {
|
||||
int state = pthread_mutex_trylock( &mMutex );
|
||||
if ( state != 0 && state != EBUSY )
|
||||
throw ThreadException( stringtf( "Unable to trylock pthread mutex: %s", strerror(errno) ) );
|
||||
|
@ -104,27 +94,23 @@ bool Mutex::locked()
|
|||
return( state == EBUSY );
|
||||
}
|
||||
|
||||
Condition::Condition( Mutex &mutex ) : mMutex( mutex )
|
||||
{
|
||||
Condition::Condition( Mutex &mutex ) : mMutex( mutex ) {
|
||||
if ( pthread_cond_init( &mCondition, NULL ) < 0 )
|
||||
throw ThreadException( stringtf( "Unable to create pthread condition: %s", strerror(errno) ) );
|
||||
Fatal( "Unable to create pthread condition: %s", strerror(errno) );
|
||||
}
|
||||
|
||||
Condition::~Condition()
|
||||
{
|
||||
Condition::~Condition() {
|
||||
if ( pthread_cond_destroy( &mCondition ) < 0 )
|
||||
throw ThreadException( stringtf( "Unable to destroy pthread condition: %s", strerror(errno) ) );
|
||||
Fatal( "Unable to destroy pthread condition: %s", strerror(errno) );
|
||||
}
|
||||
|
||||
void Condition::wait()
|
||||
{
|
||||
void Condition::wait() {
|
||||
// Locking done outside of this function
|
||||
if ( pthread_cond_wait( &mCondition, mMutex.getMutex() ) < 0 )
|
||||
throw ThreadException( stringtf( "Unable to wait pthread condition: %s", strerror(errno) ) );
|
||||
}
|
||||
|
||||
bool Condition::wait( int secs )
|
||||
{
|
||||
bool Condition::wait( int secs ) {
|
||||
// Locking done outside of this function
|
||||
Debug( 8, "Waiting for %d seconds", secs );
|
||||
struct timespec timeout = getTimeout( secs );
|
||||
|
@ -133,8 +119,7 @@ bool Condition::wait( int secs )
|
|||
return( errno != ETIMEDOUT );
|
||||
}
|
||||
|
||||
bool Condition::wait( double secs )
|
||||
{
|
||||
bool Condition::wait( double secs ) {
|
||||
// Locking done outside of this function
|
||||
struct timespec timeout = getTimeout( secs );
|
||||
if ( pthread_cond_timedwait( &mCondition, mMutex.getMutex(), &timeout ) < 0 && errno != ETIMEDOUT )
|
||||
|
@ -142,36 +127,31 @@ bool Condition::wait( double secs )
|
|||
return( errno != ETIMEDOUT );
|
||||
}
|
||||
|
||||
void Condition::signal()
|
||||
{
|
||||
void Condition::signal() {
|
||||
if ( pthread_cond_signal( &mCondition ) < 0 )
|
||||
throw ThreadException( stringtf( "Unable to signal pthread condition: %s", strerror(errno) ) );
|
||||
}
|
||||
|
||||
void Condition::broadcast()
|
||||
{
|
||||
void Condition::broadcast() {
|
||||
if ( pthread_cond_broadcast( &mCondition ) < 0 )
|
||||
throw ThreadException( stringtf( "Unable to broadcast pthread condition: %s", strerror(errno) ) );
|
||||
}
|
||||
|
||||
template <class T> const T ThreadData<T>::getValue() const
|
||||
{
|
||||
template <class T> const T ThreadData<T>::getValue() const {
|
||||
mMutex.lock();
|
||||
const T valueCopy = mValue;
|
||||
mMutex.unlock();
|
||||
return( valueCopy );
|
||||
}
|
||||
|
||||
template <class T> T ThreadData<T>::setValue( const T value )
|
||||
{
|
||||
template <class T> T ThreadData<T>::setValue( const T value ) {
|
||||
mMutex.lock();
|
||||
const T valueCopy = mValue = value;
|
||||
mMutex.unlock();
|
||||
return( valueCopy );
|
||||
}
|
||||
|
||||
template <class T> const T ThreadData<T>::getUpdatedValue() const
|
||||
{
|
||||
template <class T> const T ThreadData<T>::getUpdatedValue() const {
|
||||
Debug( 8, "Waiting for value update, %p", this );
|
||||
mMutex.lock();
|
||||
mChanged = false;
|
||||
|
@ -184,8 +164,7 @@ template <class T> const T ThreadData<T>::getUpdatedValue() const
|
|||
return( valueCopy );
|
||||
}
|
||||
|
||||
template <class T> const T ThreadData<T>::getUpdatedValue( double secs ) const
|
||||
{
|
||||
template <class T> const T ThreadData<T>::getUpdatedValue( double secs ) const {
|
||||
Debug( 8, "Waiting for value update, %.2f secs, %p", secs, this );
|
||||
mMutex.lock();
|
||||
mChanged = false;
|
||||
|
@ -198,8 +177,7 @@ template <class T> const T ThreadData<T>::getUpdatedValue( double secs ) const
|
|||
return( valueCopy );
|
||||
}
|
||||
|
||||
template <class T> const T ThreadData<T>::getUpdatedValue( int secs ) const
|
||||
{
|
||||
template <class T> const T ThreadData<T>::getUpdatedValue( int secs ) const {
|
||||
Debug( 8, "Waiting for value update, %d secs, %p", secs, this );
|
||||
mMutex.lock();
|
||||
mChanged = false;
|
||||
|
@ -212,8 +190,7 @@ template <class T> const T ThreadData<T>::getUpdatedValue( int secs ) const
|
|||
return( valueCopy );
|
||||
}
|
||||
|
||||
template <class T> void ThreadData<T>::updateValueSignal( const T value )
|
||||
{
|
||||
template <class T> void ThreadData<T>::updateValueSignal( const T value ) {
|
||||
Debug( 8, "Updating value with signal, %p", this );
|
||||
mMutex.lock();
|
||||
mValue = value;
|
||||
|
@ -223,8 +200,7 @@ template <class T> void ThreadData<T>::updateValueSignal( const T value )
|
|||
Debug( 9, "Updated value, %p", this );
|
||||
}
|
||||
|
||||
template <class T> void ThreadData<T>::updateValueBroadcast( const T value )
|
||||
{
|
||||
template <class T> void ThreadData<T>::updateValueBroadcast( const T value ) {
|
||||
Debug( 8, "Updating value with broadcast, %p", this );
|
||||
mMutex.lock();
|
||||
mValue = value;
|
||||
|
@ -243,21 +219,18 @@ Thread::Thread() :
|
|||
Debug( 1, "Creating thread" );
|
||||
}
|
||||
|
||||
Thread::~Thread()
|
||||
{
|
||||
Thread::~Thread() {
|
||||
Debug( 1, "Destroying thread %d", mPid );
|
||||
if ( mStarted )
|
||||
join();
|
||||
}
|
||||
|
||||
void *Thread::mThreadFunc( void *arg )
|
||||
{
|
||||
void *Thread::mThreadFunc( void *arg ) {
|
||||
Debug( 2, "Invoking thread" );
|
||||
|
||||
Thread *thisPtr = (Thread *)arg;
|
||||
thisPtr->status = 0;
|
||||
try
|
||||
{
|
||||
try {
|
||||
thisPtr->mThreadMutex.lock();
|
||||
thisPtr->mPid = thisPtr->id();
|
||||
thisPtr->mThreadCondition.signal();
|
||||
|
@ -268,9 +241,7 @@ void *Thread::mThreadFunc( void *arg )
|
|||
thisPtr->mRunning = false;
|
||||
Debug( 2, "Exiting thread, status %p", (void *)&(thisPtr->status) );
|
||||
return (void *)&(thisPtr->status);
|
||||
}
|
||||
catch ( const ThreadException &e )
|
||||
{
|
||||
} catch ( const ThreadException &e ) {
|
||||
Error( "%s", e.getMessage().c_str() );
|
||||
thisPtr->mRunning = false;
|
||||
Debug( 2, "Exiting thread after exception, status %p", (void *)-1 );
|
||||
|
@ -278,14 +249,12 @@ void *Thread::mThreadFunc( void *arg )
|
|||
}
|
||||
}
|
||||
|
||||
void Thread::start()
|
||||
{
|
||||
void Thread::start() {
|
||||
Debug( 1, "Starting thread" );
|
||||
if ( isThread() )
|
||||
throw ThreadException( "Can't self start thread" );
|
||||
mThreadMutex.lock();
|
||||
if ( !mStarted )
|
||||
{
|
||||
if ( !mStarted ) {
|
||||
pthread_attr_t threadAttrs;
|
||||
pthread_attr_init( &threadAttrs );
|
||||
pthread_attr_setscope( &threadAttrs, PTHREAD_SCOPE_SYSTEM );
|
||||
|
@ -294,9 +263,7 @@ void Thread::start()
|
|||
if ( pthread_create( &mThread, &threadAttrs, mThreadFunc, this ) < 0 )
|
||||
throw ThreadException( stringtf( "Can't create thread: %s", strerror(errno) ) );
|
||||
pthread_attr_destroy( &threadAttrs );
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
Error( "Attempt to start already running thread %d", mPid );
|
||||
}
|
||||
mThreadCondition.wait();
|
||||
|
@ -304,37 +271,29 @@ void Thread::start()
|
|||
Debug( 1, "Started thread %d", mPid );
|
||||
}
|
||||
|
||||
void Thread::join()
|
||||
{
|
||||
void Thread::join() {
|
||||
Debug( 1, "Joining thread %d", mPid );
|
||||
if ( isThread() )
|
||||
throw ThreadException( "Can't self join thread" );
|
||||
mThreadMutex.lock();
|
||||
if ( mPid >= 0 )
|
||||
{
|
||||
if ( mStarted )
|
||||
{
|
||||
if ( mPid >= 0 ) {
|
||||
if ( mStarted ) {
|
||||
void *threadStatus = 0;
|
||||
if ( pthread_join( mThread, &threadStatus ) < 0 )
|
||||
throw ThreadException( stringtf( "Can't join sender thread: %s", strerror(errno) ) );
|
||||
mStarted = false;
|
||||
Debug( 1, "Thread %d exited, status %p", mPid, threadStatus );
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
Warning( "Attempt to join already finished thread %d", mPid );
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
Warning( "Attempt to join non-started thread %d", mPid );
|
||||
}
|
||||
mThreadMutex.unlock();
|
||||
Debug( 1, "Joined thread %d", mPid );
|
||||
}
|
||||
|
||||
void Thread::kill( int signal )
|
||||
{
|
||||
void Thread::kill( int signal ) {
|
||||
pthread_kill( mThread, signal );
|
||||
}
|
||||
|
||||
|
|
|
@ -174,6 +174,7 @@ VideoStore::VideoStore(
|
|||
video_out_ctx->pix_fmt = AV_PIX_FMT_YUV440P;
|
||||
break;
|
||||
default:
|
||||
video_out_ctx->pix_fmt = AV_PIX_FMT_YUV420P;
|
||||
break;
|
||||
}
|
||||
// Same codec, just copy the packets, otherwise we have to decode/encode
|
||||
|
@ -542,7 +543,7 @@ VideoStore::~VideoStore() {
|
|||
}
|
||||
#endif
|
||||
int keyframe = pkt.flags & AV_PKT_FLAG_KEY;
|
||||
Debug(3, "dts:%d, pts:%d, keyframe:%d", pkt.dts, pkt.pts, keyframe );
|
||||
Debug(3, "dts:%I64d, pts:%I64d, keyframe:%d", pkt.dts, pkt.pts, keyframe );
|
||||
//pkt.dts = video_next_dts;
|
||||
pkt.pts = pkt.dts;
|
||||
//pkt.duration = video_last_duration;
|
||||
|
@ -891,7 +892,7 @@ void VideoStore::dumpPacket(AVPacket *pkt) {
|
|||
snprintf(b, sizeof(b),
|
||||
" pts: %" PRId64 ", dts: %" PRId64
|
||||
", data: %p, size: %d, sindex: %d, dflags: %04x, s-pos: %" PRId64
|
||||
", c-duration: %" PRId64 "\n",
|
||||
", duration: %" PRId64 "\n",
|
||||
pkt->pts,
|
||||
pkt->dts,
|
||||
pkt->data,
|
||||
|
@ -1057,7 +1058,7 @@ int VideoStore::writeVideoFramePacket( ZMPacket * zm_packet ) {
|
|||
}
|
||||
opkt.duration = 0;
|
||||
|
||||
Debug(3, "dts:%d, pts:%d, keyframe:%d", opkt.dts, opkt.pts, opkt.flags & AV_PKT_FLAG_KEY );
|
||||
Debug(3, "dts:%" PRId64 ", pts:%" PRId64 ", keyframe:%d", opkt.dts, opkt.pts, opkt.flags & AV_PKT_FLAG_KEY );
|
||||
write_video_packet( opkt );
|
||||
zm_av_packet_unref(&opkt);
|
||||
|
||||
|
@ -1068,7 +1069,7 @@ void VideoStore::write_video_packet( AVPacket &opkt ) {
|
|||
|
||||
if ( opkt.dts > opkt.pts ) {
|
||||
Debug(1,
|
||||
"opkt.dts(%d) must be <= opkt.pts(%d). Decompression must happen "
|
||||
"opkt.dts(%" PRId64 ") must be <= opkt.pts(%" PRId64 "). Decompression must happen "
|
||||
"before presentation.",
|
||||
opkt.dts, opkt.pts);
|
||||
opkt.dts = opkt.pts;
|
||||
|
@ -1085,7 +1086,7 @@ void VideoStore::write_video_packet( AVPacket &opkt ) {
|
|||
//av_packet_rescale_ts( &opkt, video_out_ctx->time_base, video_out_stream->time_base );
|
||||
|
||||
Debug(1,
|
||||
"writing video packet pts(%d) dts(%d) duration(%d) packet_count(%d)",
|
||||
"writing video packet pts(%" PRId64 ") dts(%" PRId64 ") duration(%" PRId64 ") packet_count(%d)",
|
||||
opkt.pts, opkt.dts, opkt.duration, packets_written );
|
||||
if ( (opkt.data == NULL) || (opkt.size < 1) ) {
|
||||
Warning("%s:%d: Mangled AVPacket: discarding frame", __FILE__, __LINE__);
|
||||
|
@ -1308,7 +1309,7 @@ int VideoStore::writeAudioFramePacket(ZMPacket *zm_packet) {
|
|||
// audio_last_dts = ipkt->dts;
|
||||
if ( opkt.dts > opkt.pts ) {
|
||||
Debug(1,
|
||||
"opkt.dts(%d) must be <= opkt.pts(%d). Decompression must happen "
|
||||
"opkt.dts(%" PRId64 ") must be <= opkt.pts(%" PRId64 "). Decompression must happen "
|
||||
"before presentation.",
|
||||
opkt.dts, opkt.pts);
|
||||
opkt.dts = opkt.pts;
|
||||
|
@ -1317,8 +1318,8 @@ int VideoStore::writeAudioFramePacket(ZMPacket *zm_packet) {
|
|||
//opkt.duration = out_frame ? out_frame->nb_samples : ipkt->duration;
|
||||
// opkt.duration = av_rescale_q(ipkt->duration, audio_in_stream->time_base,
|
||||
// audio_out_stream->time_base);
|
||||
Debug(2, "opkt.pts (%d), opkt.dts(%d) opkt.duration = (%d)", opkt.pts,
|
||||
opkt.dts, opkt.duration);
|
||||
Debug(2, "opkt.pts (%" PRId64 "), opkt.dts(%" PRId64 ") opkt.duration = (%" PRId64 ")",
|
||||
opkt.pts, opkt.dts, opkt.duration);
|
||||
|
||||
// pkt.pos: byte position in stream, -1 if unknown
|
||||
opkt.pos = -1;
|
||||
|
@ -1351,7 +1352,8 @@ int VideoStore::write_packets( zm_packetqueue &queue ) {
|
|||
|
||||
packet_count += 1;
|
||||
//Write the packet to our video store
|
||||
Debug(2, "Writing queued packet stream: %d KEY %d, remaining (%d)", avp->stream_index, avp->flags & AV_PKT_FLAG_KEY, queue.size() );
|
||||
Debug(2, "Writing queued packet stream: %d KEY %d, remaining (%d)",
|
||||
avp->stream_index, avp->flags & AV_PKT_FLAG_KEY, queue.size() );
|
||||
int ret = this->writePacket( queued_packet );
|
||||
if ( ret < 0 ) {
|
||||
//Less than zero and we skipped a frame
|
||||
|
|
Loading…
Reference in New Issue