Skip to content

Commit

Permalink
Final prep for 1.5.2
Browse files Browse the repository at this point in the history
  • Loading branch information
mickelson committed May 10, 2015
1 parent e323a5f commit 0bcfde0
Show file tree
Hide file tree
Showing 4 changed files with 80 additions and 77 deletions.
17 changes: 14 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@
#
# Uncomment next line for Windows static cross-compile build (mxe)
#WINDOWS_STATIC=1
#
# Uncomment the next line if you wish to use SFML to load images instead
# of FFmpeg (has no effect if NO_MOVIE=1)
#SFML_IMAGES=1
###############################

#FE_DEBUG=1
Expand Down Expand Up @@ -158,6 +162,7 @@ ifeq ($(WINDOWS_STATIC),1)
LIBS += $(shell $(PKG_CONFIG) --static --libs sfml)
CFLAGS += -DSFML_STATIC $(shell $(PKG_CONFIG) --static --cflags sfml)
FE_WINDOWS_COMPILE=1

else

ifeq ($(NO_NET),1)
Expand All @@ -170,12 +175,14 @@ else
-lsfml-window \
-lsfml-network \
-lsfml-system

_DEP += fe_net.hpp
_OBJ += fe_net.o
endif
endif

ifneq ($(NO_NET),1)
_DEP += fe_net.hpp
_OBJ += fe_net.o
endif

ifeq ($(FE_WINDOWS_COMPILE),1)
CFLAGS += -mconsole
EXE_EXT = .exe
Expand Down Expand Up @@ -252,6 +259,10 @@ else
_DEP += media.hpp
_OBJ += media.o

ifeq ($(SFML_IMAGES),1)
FE_FLAGS += -DSFML_IMAGES
endif

CFLAGS += -I$(EXTLIBS_DIR)/audio/include
AUDIO = $(OBJ_DIR)/libaudio.a
endif
Expand Down
96 changes: 42 additions & 54 deletions src/fe_image.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -275,56 +275,60 @@ bool FeTextureContainer::common_load(
std::vector<std::string> &image_names )
{
bool loaded=false;

#ifndef NO_MOVIE
if ( m_video_flags & VF_DisableVideo )
non_image_names.clear();

#ifndef SFML_IMAGES
while ( !image_names.empty() )
{
non_image_names.push_back( image_names.back() );
image_names.pop_back();
}
#endif

ASSERT( !m_movie ); // m_movie should always be empty at this point...

if ( !(m_video_flags & VF_DisableVideo) )
std::string movie_file;
for ( std::vector<std::string>::iterator itr = non_image_names.begin();
itr != non_image_names.end(); ++itr )
{
std::string movie_file;
for ( std::vector<std::string>::iterator itr = non_image_names.begin();
itr != non_image_names.end(); ++itr )
if ( FeMedia::is_supported_media_file( *itr ) )
{
if ( FeMedia::is_supported_media_file( *itr ) )
{
movie_file = (*itr);
break;
}
movie_file = (*itr);
break;
}
}

if ( !movie_file.empty() )
{
m_movie = new FeMedia( FeMedia::AudioVideo );
if ( !movie_file.empty() )
{
m_movie = new FeMedia( FeMedia::AudioVideo );

if (!m_movie->openFromFile( movie_file ))
{
std::cout << "ERROR loading video: "
<< movie_file << std::endl;
}
else
if (!m_movie->openFromFile( movie_file, &m_texture ))
{
std::cout << "ERROR loading video: "
<< movie_file << std::endl;
}
else
{
loaded = true;
m_file_name = movie_file;

if ( !m_movie->is_multiframe() )
{
sf::Texture *t = m_movie->get_texture();
ASSERT( t ); // openFromFile should create this!
if ( t ) t->setSmooth( m_texture.isSmooth() );
m_movie_status = -1; // don't play if there is only one frame

loaded = true;
m_file_name = movie_file;

if ( m_movie->number_of_frames() == 1 )
{
m_movie_status = -1; // don't play if there is only one frame

// if there is only one frame, then we can update the texture immediately
// (the frame will have been preloaded) and delete our movie object now
notify_texture_change();
delete m_movie;
m_movie = NULL;
}
else if (m_video_flags & VF_NoAutoStart)
m_movie_status = 0; // 0=loaded but not on track to play
else
m_movie_status = 1; // 1=on track to be played
// if there is only one frame, then we can update the texture immediately
// (the frame will have been preloaded) and delete our movie object now
notify_texture_change();
delete m_movie;
m_movie = NULL;
}
else if (m_video_flags & VF_NoAutoStart)
m_movie_status = 0; // 0=loaded but not on track to play
else
m_movie_status = 1; // 1=on track to be played
}
}
#endif
Expand All @@ -351,14 +355,6 @@ bool FeTextureContainer::common_load(

const sf::Texture &FeTextureContainer::get_texture()
{
#ifndef NO_MOVIE
if ( m_movie )
{
const sf::Texture *t = m_movie->get_texture();
if ( t ) return *t;
}
#endif

return m_texture;
}

Expand Down Expand Up @@ -689,14 +685,6 @@ void FeTextureContainer::clear()

void FeTextureContainer::set_smooth( bool s )
{
#ifndef NO_MOVIE
if ( m_movie )
{
sf::Texture *t = m_movie->get_texture();
if ( t )
t->setSmooth( s );
}
#endif
m_texture.setSmooth( s );
}

Expand Down
38 changes: 21 additions & 17 deletions src/media.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -157,8 +157,8 @@ class FeVideoImp : public FeBaseStream
public:
bool run_video_thread;
sf::Time time_base;
sf::Texture display_texture;
sf::Clock video_timer;
sf::Texture *display_texture;
SwsContext *sws_ctx;
int sws_flags;

Expand Down Expand Up @@ -292,6 +292,7 @@ FeVideoImp::FeVideoImp( FeMedia *p )
m_video_thread( &FeVideoImp::video_thread, this ),
m_parent( p ),
run_video_thread( false ),
display_texture( NULL ),
sws_ctx( NULL ),
sws_flags( SWS_FAST_BILINEAR ),
display_frame( NULL )
Expand Down Expand Up @@ -420,7 +421,7 @@ void FeVideoImp::preload()
my_pict->linesize );

sf::Lock l( image_swap_mutex );
display_texture.update( my_pict->data[0] );
display_texture->update( my_pict->data[0] );

keep_going = false;

Expand Down Expand Up @@ -679,13 +680,6 @@ void FeMedia::init_av()
}
}

sf::Texture *FeMedia::get_texture()
{
if ( m_video )
return &(m_video->display_texture);
return NULL;
}

sf::Time FeMedia::get_video_time()
{
//
Expand Down Expand Up @@ -795,7 +789,7 @@ void FeMedia::setVolume(float volume)
sf::SoundStream::setVolume( volume );
}

bool FeMedia::openFromFile( const std::string &name )
bool FeMedia::openFromFile( const std::string &name, sf::Texture *outt )
{
close();
init_av();
Expand Down Expand Up @@ -878,6 +872,9 @@ bool FeMedia::openFromFile( const std::string &name )
{
m_format_ctx->streams[stream_id]->codec->workaround_bugs = FF_BUG_AUTODETECT;

// Note also: http://trac.ffmpeg.org/ticket/4404
m_format_ctx->streams[stream_id]->codec->thread_count=1;

if ( avcodec_open2( m_format_ctx->streams[stream_id]->codec,
dec, NULL ) < 0 )
{
Expand All @@ -893,10 +890,9 @@ bool FeMedia::openFromFile( const std::string &name )
m_video->time_base = sf::seconds(
av_q2d(m_format_ctx->streams[stream_id]->time_base) );

m_video->display_texture = sf::Texture();
m_video->display_texture.create( m_video->codec_ctx->width,
m_video->display_texture = outt;
m_video->display_texture->create( m_video->codec_ctx->width,
m_video->codec_ctx->height );
m_video->display_texture.setSmooth( true );
m_video->preload();
}
}
Expand Down Expand Up @@ -951,7 +947,7 @@ bool FeMedia::tick()
sf::Lock l( m_video->image_swap_mutex );
if ( m_video->display_frame )
{
m_video->display_texture.update( m_video->display_frame );
m_video->display_texture->update( m_video->display_frame );
m_video->display_frame = NULL;
return true;
}
Expand Down Expand Up @@ -1174,12 +1170,20 @@ bool FeMedia::is_supported_media_file( const std::string &filename )
}


int FeMedia::number_of_frames() const
bool FeMedia::is_multiframe() const
{
if ( m_video && m_format_ctx )
return m_format_ctx->streams[ m_video->stream_id ]->nb_frames;
{
if (( m_format_ctx->streams[ m_video->stream_id ]->nb_frames > 1 )
#ifdef AV_CODEC_ID_APNG
|| ( m_format_ctx->streams[ m_video->stream_id ]->id == AV_CODEC_ID_APNG )
#endif
|| ( m_format_ctx->streams[ m_video->stream_id ]->id == AV_CODEC_ID_GIF ))
return true;

return 0;
}

return false;
}

sf::Time FeMedia::get_duration() const
Expand Down
6 changes: 3 additions & 3 deletions src/media.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ friend class FeVideoImp;
FeMedia( Type t );
~FeMedia();

bool openFromFile( const std::string &name );
sf::Texture *get_texture();
bool openFromFile( const std::string &name,
sf::Texture *out_texture=NULL );

using sf::SoundStream::setPosition;
using sf::SoundStream::getPosition;
Expand All @@ -71,7 +71,7 @@ friend class FeVideoImp;
void setVolume(float volume);

bool is_playing();
int number_of_frames() const;
bool is_multiframe() const;

sf::Time get_video_time();
sf::Time get_duration() const;
Expand Down

0 comments on commit 0bcfde0

Please sign in to comment.