[Player-cvs] hxmm/ffmpeg Umakefil, NONE, 1.1 cmdutils.c, NONE, 1.1 cmdutils.h, NONE, 1.1 ffplay.c, NONE, 1.1 ffplay.h, NONE, 1.1 hxffmpegfactory.c, NONE, 1.1 hxffmpegplayer.c, NONE, 1.1 hxffmpegplayer.h, NONE, 1.1

[Player-cvs] hxmm/ffmpeg Umakefil, NONE, 1.1 cmdutils.c, NONE, 1.1 cmdutils.h, NONE, 1.1 ffplay.c, NONE, 1.1 ffplay.h, NONE, 1.1 hxffmpegfactory.c, NONE, 1.1 hxffmpegplayer.c, NONE, 1.1 hxffmpegplayer.h, NONE, 1.1

rggammon at helixcommunity.org rggammon at helixcommunity.org
Fri Jul 15 17:43:40 PDT 2005


Update of /cvsroot/player/hxmm/ffmpeg
In directory cvs:/tmp/cvs-serv18588/ffmpeg

Added Files:
	Umakefil cmdutils.c cmdutils.h ffplay.c ffplay.h 
	hxffmpegfactory.c hxffmpegplayer.c hxffmpegplayer.h 
Log Message:
Adding the ffmpeg backend


--- NEW FILE: cmdutils.c ---
/*
 * Various utilities for command line tools
 * Copyright (c) 2000-2003 Fabrice Bellard
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */
#include "avformat.h"
#include "common.h"

#include "cmdutils.h"

void print_error(const char *filename, int err)
{
    switch(err) {
    case AVERROR_NUMEXPECTED:
        fprintf(stderr, "%s: Incorrect image filename syntax.\n"
                "Use '%%d' to specify the image number:\n"
                "  for img1.jpg, img2.jpg, ..., use 'img%%d.jpg';\n"
                "  for img001.jpg, img002.jpg, ..., use 'img%%03d.jpg'.\n", 
                filename);
        break;
    case AVERROR_INVALIDDATA:
        fprintf(stderr, "%s: Error while parsing header\n", filename);
        break;
    case AVERROR_NOFMT:
        fprintf(stderr, "%s: Unknown format\n", filename);
        break;
    case AVERROR_IO:
        fprintf(stderr, "%s: I/O error occured\n"
	        "Usually that means that input file is truncated and/or corrupted.\n",
		filename);
        break;
    case AVERROR_NOMEM:
        fprintf(stderr, "%s: memory allocation error occured\n", filename);
        break;
    default:
        fprintf(stderr, "%s: Error while opening file\n", filename);
        break;
    }
}

--- NEW FILE: cmdutils.h ---
#ifndef _CMD_UTILS_H
#define _CMD_UTILS_H

typedef struct {
    const char *name;
    int flags;
#define HAS_ARG    0x0001
#define OPT_BOOL   0x0002
#define OPT_EXPERT 0x0004
#define OPT_STRING 0x0008
#define OPT_VIDEO  0x0010
#define OPT_AUDIO  0x0020
#define OPT_GRAB   0x0040
#define OPT_INT    0x0080
#define OPT_FLOAT  0x0100
    union {
        void (*func_arg)(const char *);
        int *int_arg;
        char **str_arg;
        float *float_arg;
    } u;
    const char *help;
    const char *argname;
} OptionDef;

void show_help_options(const OptionDef *options, const char *msg, int mask, int value);
void parse_options(int argc, char **argv, const OptionDef *options);
void parse_arg_file(const char *filename);
void print_error(const char *filename, int err);

#endif /* _CMD_UTILS_H */

--- NEW FILE: ffplay.c ---
/*
 * FFplay : Simple Media Player based on the ffmpeg libraries
 * Copyright (c) 2003 Fabrice Bellard
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

[...1730 lines suppressed...]
    /* register all codecs, demux and protocols */
    av_register_all();

    flags = SDL_INIT_VIDEO | SDL_INIT_AUDIO | SDL_INIT_TIMER | SDL_INIT_EVENTTHREAD | SDL_INIT_NOPARACHUTE;

    if (SDL_Init (flags)) {
        fprintf(stderr, "Could not initialize SDL - %s\n", SDL_GetError());
        return -1;
    }

    screen = SDL_SetVideoMode(attr.width, attr.height, 0,  
                              SDL_HWSURFACE|SDL_RESIZABLE|SDL_ASYNCBLIT|SDL_HWACCEL); 

    SDL_EventState(SDL_ACTIVEEVENT, SDL_IGNORE);
    SDL_EventState(SDL_MOUSEMOTION, SDL_IGNORE);
    SDL_EventState(SDL_SYSWMEVENT, SDL_IGNORE);
    SDL_EventState(SDL_USEREVENT, SDL_IGNORE);

    return 0;
}

--- NEW FILE: hxffmpegplayer.h ---
/* ***** BEGIN LICENSE BLOCK *****
 * Source last modified: $Id: hxffmpegplayer.h,v 1.1 2005/07/16 00:43:37 rggammon Exp $
 * 
 * Portions Copyright (c) 1995-2005 RealNetworks, Inc. All Rights Reserved.
 * 
 * The contents of this file, and the files included with this file,
 * are subject to the current version of the RealNetworks Public
 * Source License (the "RPSL") available at
 * http://www.helixcommunity.org/content/rpsl unless you have licensed
 * the file under the current version of the RealNetworks Community
 * Source License (the "RCSL") available at
 * http://www.helixcommunity.org/content/rcsl, in which case the RCSL
 * will apply. You may also obtain the license terms directly from
 * RealNetworks.  You may not use this file except in compliance with
 * the RPSL or, if you have a valid RCSL with RealNetworks applicable
 * to this file, the RCSL.  Please see the applicable RPSL or RCSL for
 * the rights, obligations and limitations governing use of the
 * contents of the file.
 * 
 * Alternatively, the contents of this file may be used under the
 * terms of the GNU Lesser General Public License Version 2 or later
 * (the "LGPL") in which case the provisions of the LGPL are applicable
 * instead of those above. If you wish to allow use of your version of
 * this file only under the terms of the LGPL, and not to allow others
 * to use your version of this file under the terms of either the RPSL
 * or RCSL, indicate your decision by deleting the provisions above
 * and replace them with the notice and other provisions required by
 * the LGPL. If you do not delete the provisions above, a recipient may
 * use your version of this file under the terms of any one of the
 * RPSL, the RCSL or the LGPL.
 * 
 * This file is part of the Helix DNA Technology. RealNetworks is the
 * developer of the Original Code and owns the copyrights in the
 * portions it created.
 * 
 * This file, and the files included with this file, is distributed
 * and made available on an 'AS IS' basis, WITHOUT WARRANTY OF ANY
 * KIND, EITHER EXPRESS OR IMPLIED, AND REALNETWORKS HEREBY DISCLAIMS
 * ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES
 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET
 * ENJOYMENT OR NON-INFRINGEMENT.
 * 
 * Technology Compatibility Kit Test Suite(s) Location:
 *    http://www.helixcommunity.org/content/tck
 * 
 * Contributor(s):
 * 
 * ***** END LICENSE BLOCK ***** */

#ifndef _HX_FFMPEG_PLAYER_H_
#define _HX_FFMPEG_PLAYER_H_

#include <gtk/gtk.h>

#include "ffplay.h"

G_BEGIN_DECLS

typedef struct HXFFMpegPlayer HXFFMpegPlayer;
typedef struct HXFFMpegPlayerClass HXFFMpegPlayerClass;

GType hx_ffmpeg_player_get_type (void);

typedef enum _HXFFMpegPlayerState
{
    FFMPEG_STATE_STOPPED,
    FFMPEG_STATE_PAUSED,
    FFMPEG_STATE_PLAYING
} HXFFMpegPlayerState;

struct HXFFMpegPlayer
{
    GObject parent;

    GtkWidget* drawing_area;
    
    VideoState* video_state;
    
    gint timer_id;

    gboolean ffmpeg_initialized;
    gboolean is_seeking;

    gchar* filename;
    
    HXFFMpegPlayerState state;
};

struct HXFFMpegPlayerClass
{
    GtkPlugClass parent;
};

#define HX_TYPE_FFMPEG_PLAYER           (hx_ffmpeg_player_get_type ())
#define HX_FFMPEG_PLAYER(object)        (G_TYPE_CHECK_INSTANCE_CAST ((object), HX_TYPE_FFMPEG_PLAYER, HXFFMpegPlayer))
#define HX_FFMPEG_PLAYER_CLASS(klass)   (G_TYPE_CHECK_CLASS_CAST ((klass), HX_TYPE_FFMPEG_PLAYER, HXFFMpegPlayerClass))
#define HX_IS_FFMPEG_PLAYER(object)     (G_TYPE_CHECK_INSTANCE_TYPE ((object), HX_TYPE_FFMPEG_PLAYER))
#define HX_IS_FFMPEG_PLAYER_CLASS(klass)(G_TYPE_CHECK_CLASS_TYPE ((klass), HX_TYPE_FFMPEG_PLAYER))
#define HX_FFMPEG_PLAYER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), HX_TYPE_FFMPEG_PLAYER, HXFFMpegPlayerClass))


HXFFMpegPlayer* hx_ffmpeg_player_new           (const gchar* license);

G_END_DECLS

#endif

--- NEW FILE: ffplay.h ---
/*
 * FFplay : Simple Media Player based on the ffmpeg libraries
 * Copyright (c) 2003 Fabrice Bellard
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

#ifndef _FFPLAY_H_
#define _FFPLAY_H_

#include <X11/Xlib.h>

#include "avformat.h"

struct _VideoState;
typedef struct _VideoState VideoState;

void        stream_seek           (VideoState    *is,
                                   int64_t        pos,
                                   int            rel);
int         stream_is_done        (VideoState    *is);

void        stream_pause          (VideoState    *is);
int         stream_component_open (VideoState    *is,
                                   int            stream_index);
void        stream_component_close(VideoState    *is,
                                   int            stream_index);
VideoState *stream_open           (const char    *filename,
                                   AVInputFormat *iformat);
void        stream_close          (VideoState    *is);
void        stream_process_event  (void);
int         stream_init           (Display       *dpy,
                                   XID            xid);
void        stream_resize_video   (VideoState*    is,
                                   int            width,
                                   int            height);
#endif

--- NEW FILE: Umakefil ---
# 
# ***** BEGIN LICENSE BLOCK *****
# Source last modified: $Id: Umakefil,v 1.1 2005/07/16 00:43:37 rggammon Exp $
# 
# Portions Copyright (c) 1995-2005 RealNetworks, Inc. All Rights Reserved.
# 
# The contents of this file, and the files included with this file,
# are subject to the current version of the RealNetworks Public
# Source License (the "RPSL") available at
# http://www.helixcommunity.org/content/rpsl unless you have licensed
# the file under the current version of the RealNetworks Community
# Source License (the "RCSL") available at
# http://www.helixcommunity.org/content/rcsl, in which case the RCSL
# will apply. You may also obtain the license terms directly from
# RealNetworks.  You may not use this file except in compliance with
# the RPSL or, if you have a valid RCSL with RealNetworks applicable
# to this file, the RCSL.  Please see the applicable RPSL or RCSL for
# the rights, obligations and limitations governing use of the
# contents of the file.
# 
# Alternatively, the contents of this file may be used under the
# terms of the GNU General Public License Version 2 or later (the
# "GPL") in which case the provisions of the GPL are applicable
# instead of those above. If you wish to allow use of your version of
# this file only under the terms of the GPL, and not to allow others
# to use your version of this file under the terms of either the RPSL
# or RCSL, indicate your decision by deleting the provisions above
# and replace them with the notice and other provisions required by
# the GPL. If you do not delete the provisions above, a recipient may
# use your version of this file under the terms of any one of the
# RPSL, the RCSL or the GPL.
# 
# This file is part of the Helix DNA Technology. RealNetworks is the
# developer of the Original Code and owns the copyrights in the
# portions it created.
# 
# This file, and the files included with this file, is distributed
# and made available on an 'AS IS' basis, WITHOUT WARRANTY OF ANY
# KIND, EITHER EXPRESS OR IMPLIED, AND REALNETWORKS HEREBY DISCLAIMS
# ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES
# OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET
# ENJOYMENT OR NON-INFRINGEMENT.
# 
# Technology Compatibility Kit Test Suite(s) Location:
#    http://www.helixcommunity.org/content/tck
# 
# Contributor(s):
# 
# ***** END LICENSE BLOCK *****
# 

UmakefileVersion(2,1)

# grab flags from pkgconfig
import shell
import string

# see if we're using the target gtk version (triggers setting of the
# DISABLE_DEPRECATED flag)

(exitstatus, gtk_mod_version) = shell.run("pkg-config --modversion gtk+-2.0")
if exitstatus != 0:
	e = err.Error()
	e.Set("pkg-config failed")
	raise err.error, e

if string.find(gtk_mod_version, "2.0") == 0:
	project.AddDefines('G_DISABLE_DEPRECATED',
					   'GDK_DISABLE_DEPRECATED',
					   'GTK_DISABLE_DEPRECATED')

pkg_modules = "gtk+-2.0"

if project.IsDefined('HELIX_FEATURE_LIBGLADE'):
	pkg_modules = pkg_modules + " libglade-2.0 gmodule-2.0"

(exitstatus, gtk_config_output_cflags) = shell.run("pkg-config --cflags " + pkg_modules)
(exitstatus, gtk_config_output_ldflags) = shell.run("pkg-config --libs " + pkg_modules)

gtk_cflags = string.split(gtk_config_output_cflags)
gtk_ldflags = string.split(gtk_config_output_ldflags)

gtk_ld_paths = []
gtk_libs = []
gtk_includes = []
gtk_defines = []
gtk_other_cflags = ""
gtk_other_ldflags = ""

# RGG: Really, we could just pass all the pkg-config arguments as
# "other". I originally wrote the parsing here to deal with the 
# fact that I needed to add -L arguments to the linker, and didn't 
# know about the project.AddDynamicLibraries hack. 

for x in gtk_cflags:
		if x[0:2] == '-I':
				gtk_includes[-1:-1] = [ x[2:] ]
		elif x[0:2] == '-D':
				gtk_defines[-1:-1] = [ x[2:] ]
		else:
				gtk_other_cflags = gtk_other_cflags + " " + x

for x in gtk_ldflags:
		if x[0:2] == '-l':
				gtk_libs[-1:-1] = [ x[2:] ]
		elif x[0:2] == '-L':
				gtk_ld_paths[-1:-1] = [ x ]
		else:
				gtk_other_ldflags = gtk_other_ldflags + " " + x                

# add the flags
project.AddSystemLibraries(gtk_libs)
project.AddIncludes(gtk_includes)
project.AddSystemPaths(gtk_ld_paths)
project.AddDefines(gtk_defines)

platform.cc.args["default"] = platform.cc.args["default"] + " " + gtk_other_cflags 
platform.cxx.args["default"] = platform.cxx.args["default"] + " " + gtk_other_cflags

# XXXRGG: This is a hack
# platform.link.args["default"] = platform.link.args["default"] + " " + gtk_other_ldflags
project.AddDynamicLibraries(gtk_other_ldflags)

project.AddSources("cmdutils.c",
                   "ffplay.c",
                   "hxffmpegfactory.c",
                   "hxffmpegplayer.c")

ffmpeg_path = GetSDKPath("ffmpeg")
project.AddIncludes(ffmpeg_path + "/include/ffmpeg")
project.AddDynamicLibraries("-L" + ffmpeg_path + "/lib")
project.AddDynamicLibraries('-lavcodec -lavformat')

sdl_path = GetSDKPath("sdl")
project.AddIncludes(sdl_path + "/include/SDL")
project.AddDynamicLibraries("-L" + sdl_path + "/lib")
project.AddDynamicLibraries("-lSDL")

dbus_path = GetSDKPath("dbus")
project.AddIncludes(dbus_path + "/include/dbus-1.0")
project.AddLibraries(dbus_path + "/lib/libdbus-1.a",
                     dbus_path + "/lib/libdbus-glib-1.a")

project.AddModuleIncludes("player/hxmm/common/pub")
project.AddModuleIncludes("player/common/gtk/pub")

project.AddModuleLibraries("player/common/gtk[libgtkhxplay]")
project.AddModuleLibraries("player/hxmm/common[libhxmm]")

ProgramTarget("hxffmpegfactory")

--- NEW FILE: hxffmpegplayer.c ---
/* ***** BEGIN LICENSE BLOCK *****
 * Source last modified: $Id: hxffmpegplayer.c,v 1.1 2005/07/16 00:43:37 rggammon Exp $
 * 
 * Portions Copyright (c) 1995-2005 RealNetworks, Inc. All Rights Reserved.
 * 
 * The contents of this file, and the files included with this file,
 * are subject to the current version of the RealNetworks Public
 * Source License (the "RPSL") available at
 * http://www.helixcommunity.org/content/rpsl unless you have licensed
 * the file under the current version of the RealNetworks Community
 * Source License (the "RCSL") available at
 * http://www.helixcommunity.org/content/rcsl, in which case the RCSL
 * will apply. You may also obtain the license terms directly from
 * RealNetworks.  You may not use this file except in compliance with
 * the RPSL or, if you have a valid RCSL with RealNetworks applicable
 * to this file, the RCSL.  Please see the applicable RPSL or RCSL for
 * the rights, obligations and limitations governing use of the
 * contents of the file.
 * 
 * Alternatively, the contents of this file may be used under the
 * terms of the GNU Lesser General Public License Version 2 or later
 * (the "LGPL") in which case the provisions of the LGPL are applicable
 * instead of those above. If you wish to allow use of your version of
 * this file only under the terms of the LGPL, and not to allow others
 * to use your version of this file under the terms of either the RPSL
 * or RCSL, indicate your decision by deleting the provisions above
 * and replace them with the notice and other provisions required by
 * the LGPL. If you do not delete the provisions above, a recipient may
 * use your version of this file under the terms of any one of the
 * RPSL, the RCSL or the LGPL.
 * 
 * This file is part of the Helix DNA Technology. RealNetworks is the
 * developer of the Original Code and owns the copyrights in the
 * portions it created.
 * 
 * This file, and the files included with this file, is distributed
 * and made available on an 'AS IS' basis, WITHOUT WARRANTY OF ANY
 * KIND, EITHER EXPRESS OR IMPLIED, AND REALNETWORKS HEREBY DISCLAIMS
 * ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES
 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET
 * ENJOYMENT OR NON-INFRINGEMENT.
 * 
 * Technology Compatibility Kit Test Suite(s) Location:
 *    http://www.helixcommunity.org/content/tck
 * 
 * Contributor(s):
 * 
 * ***** END LICENSE BLOCK ***** */

#include "hxffmpegplayer.h"
#include "hxbasicplayback.h"

#include <gdk/gdkx.h>

#include <string.h>

#define SLEEP_TIME 10

static GtkPlugClass* g_parent_class = NULL;

static void     hx_ffmpeg_drawing_area_realize   (GtkWidget*      widget,
                                                  HXFFMpegPlayer* player);
static void     hx_ffmpeg_drawing_area_unrealize (GtkWidget*      widget,
                                                  HXFFMpegPlayer* player);
static gboolean hx_ffmpeg_drawing_area_configure (GtkWidget*      widget,
                                                  GdkEventConfigure* event,
                                                  HXFFMpegPlayer* player);
/* HXBasicPlayback implementation */
static void     hx_ffmpeg_player_open_location       (HXBasicPlayback* playback,
                                                      const gchar*     location);    
static gchar*   hx_ffmpeg_player_get_opened_location (HXBasicPlayback* playback);

static GtkWidget* hx_ffmpeg_player_get_video_area    (HXBasicPlayback* player);

static void     hx_ffmpeg_player_play    (HXBasicPlayback* playback);
static void     hx_ffmpeg_player_pause   (HXBasicPlayback* playback);
static void     hx_ffmpeg_player_stop    (HXBasicPlayback* playback);

static void     hx_ffmpeg_player_start_seeking (HXBasicPlayback* playback);
static void     hx_ffmpeg_player_seek          (HXBasicPlayback* playback,
                                                gint64           position);
static void     hx_ffmpeg_player_stop_seeking  (HXBasicPlayback* playback);

static gboolean hx_ffmpeg_player_is_playing  (HXBasicPlayback* playback);
static gboolean hx_ffmpeg_player_is_paused   (HXBasicPlayback* playback);
static gboolean hx_ffmpeg_player_is_stopped  (HXBasicPlayback* playback);
static gboolean hx_ffmpeg_player_is_seeking  (HXBasicPlayback* playback);

static gboolean hx_ffmpeg_player_can_play    (HXBasicPlayback* playback);
static gboolean hx_ffmpeg_player_can_pause   (HXBasicPlayback* playback);
static gboolean hx_ffmpeg_player_can_stop    (HXBasicPlayback* playback);
static gboolean hx_ffmpeg_player_can_seek    (HXBasicPlayback* playback);

static gboolean hx_ffmpeg_player_get_current_clip_basic_metadata (HXBasicPlayback*    playback,
                                                                  HXBasicMetadataType metadata,
                                                                  GValue*             value);

static gint64   hx_ffmpeg_player_get_length             (HXBasicPlayback* playback);
static gint64   hx_ffmpeg_player_get_position	        (HXBasicPlayback* playback);
static gboolean hx_ffmpeg_player_is_live                (HXBasicPlayback* player);
static gboolean hx_ffmpeg_player_is_infinite_duration   (HXBasicPlayback* player);

static gboolean hx_ffmpeg_player_can_set_volume  (HXBasicPlayback* playback);
static gboolean hx_ffmpeg_player_can_set_mute    (HXBasicPlayback* playback);
    
static void     hx_ffmpeg_player_set_volume_percent (HXBasicPlayback* playback,
                                                     gint             volume);
static gint     hx_ffmpeg_player_get_volume_percent (HXBasicPlayback* playback);

static void     hx_ffmpeg_player_set_mute        (HXBasicPlayback* playback,
                                                  gboolean         mute);
static gboolean hx_ffmpeg_player_get_mute        (HXBasicPlayback* playback);

static void     hx_ffmpeg_player_get_ideal_visual_content_size  (HXBasicPlayback* player,
                                                                 gint*            width,
                                                                 gint*            height);
static gboolean hx_ffmpeg_player_has_visual_content (HXBasicPlayback* player);

static void     hx_ffmpeg_player_basic_playback_init (HXBasicPlaybackIface *iface);

G_DEFINE_TYPE_WITH_CODE(HXFFMpegPlayer, hx_ffmpeg_player, G_TYPE_OBJECT,
                        {
                            G_IMPLEMENT_INTERFACE (HX_TYPE_BASIC_PLAYBACK,
                                                   hx_ffmpeg_player_basic_playback_init);
                        });

/* ffmpeg functions */

static gboolean
hx_ffmpeg_player_pump (gpointer data)
{
    HXFFMpegPlayer* player = HX_FFMPEG_PLAYER(data);

    g_return_val_if_fail(player != NULL, FALSE);
    
    stream_process_event();
    
    if(stream_is_done(player->video_state))
    {
        g_signal_emit_by_name(player, "stop");
        g_signal_emit_by_name(player, "state_changed");
    }
    
    return TRUE; // do not remove this callback
}

static void
hx_ffmpeg_player_finalize (GObject *object)
{
    (G_OBJECT_CLASS (hx_ffmpeg_player_parent_class)->finalize) (object);
}

static void
hx_ffmpeg_player_init (HXFFMpegPlayer *player)
{
    player->drawing_area = NULL;
    player->video_state = NULL;
    player->timer_id = -1;
    player->ffmpeg_initialized = FALSE;
    player->filename = NULL;
    player->state = FFMPEG_STATE_STOPPED;
    player->is_seeking = FALSE;
}

static void
hx_ffmpeg_player_basic_playback_init (HXBasicPlaybackIface *iface)
{
    iface->open_location = hx_ffmpeg_player_open_location;
    iface->get_opened_location = hx_ffmpeg_player_get_opened_location;
    iface->get_video_area = hx_ffmpeg_player_get_video_area;    
    iface->play = hx_ffmpeg_player_play;
    iface->play = hx_ffmpeg_player_play;
    iface->pause = hx_ffmpeg_player_pause;
    iface->stop = hx_ffmpeg_player_stop;
    iface->start_seeking = hx_ffmpeg_player_start_seeking;
    iface->seek = hx_ffmpeg_player_seek;
    iface->stop_seeking = hx_ffmpeg_player_stop_seeking;
    iface->is_playing = hx_ffmpeg_player_is_playing;
    iface->is_paused = hx_ffmpeg_player_is_paused;
    iface->is_stopped = hx_ffmpeg_player_is_stopped;
    iface->is_seeking = hx_ffmpeg_player_is_seeking;
    iface->can_play = hx_ffmpeg_player_can_play;
    iface->can_pause = hx_ffmpeg_player_can_pause;
    iface->can_stop = hx_ffmpeg_player_can_stop;
    iface->can_seek = hx_ffmpeg_player_can_seek;
    iface->get_current_clip_basic_metadata = hx_ffmpeg_player_get_current_clip_basic_metadata;
    iface->get_length = hx_ffmpeg_player_get_length;
    iface->get_position = hx_ffmpeg_player_get_position;
    iface->is_live = hx_ffmpeg_player_is_live;
    iface->is_infinite_duration = hx_ffmpeg_player_is_infinite_duration;
    iface->can_set_volume = hx_ffmpeg_player_can_set_volume;
    iface->can_set_mute = hx_ffmpeg_player_can_set_mute;
    iface->set_volume_percent = hx_ffmpeg_player_set_volume_percent;
    iface->get_volume_percent = hx_ffmpeg_player_get_volume_percent;
    iface->set_mute = hx_ffmpeg_player_set_mute;
    iface->get_mute = hx_ffmpeg_player_get_mute;
    iface->get_ideal_visual_content_size = hx_ffmpeg_player_get_ideal_visual_content_size;
    iface->has_visual_content = hx_ffmpeg_player_has_visual_content;
}

static void
hx_ffmpeg_player_class_init (HXFFMpegPlayerClass *player_class)
{
    GObjectClass *gobject_class = G_OBJECT_CLASS (player_class);
        
    g_parent_class = (GtkPlugClass*) g_type_class_peek_parent (player_class);
    
    gobject_class->finalize = hx_ffmpeg_player_finalize;
}

HXFFMpegPlayer*
hx_ffmpeg_player_new (const gchar* license)
{
    HXFFMpegPlayer* player = NULL;
    if(license)
    {
        GdkColor black;
        gdk_color_parse("black", &black);
        
        player = (HXFFMpegPlayer*)g_object_new(HX_TYPE_FFMPEG_PLAYER, NULL);

        player->drawing_area = gtk_drawing_area_new();
        gtk_widget_modify_bg(player->drawing_area,GTK_STATE_NORMAL, &black);
        
        g_signal_connect( G_OBJECT(player->drawing_area), "realize",
                          G_CALLBACK(hx_ffmpeg_drawing_area_realize), G_OBJECT(player));

        g_signal_connect( G_OBJECT(player->drawing_area), "unrealize",
                          G_CALLBACK(hx_ffmpeg_drawing_area_unrealize), G_OBJECT(player));

        g_signal_connect( G_OBJECT(player->drawing_area), "configure-event",
                          G_CALLBACK(hx_ffmpeg_drawing_area_configure), G_OBJECT(player));

        gtk_widget_show(player->drawing_area);        
    }    
    
    return player;
}


static gboolean
hx_ffmpeg_drawing_area_configure (GtkWidget *widget,
                                  GdkEventConfigure *event,
                                  HXFFMpegPlayer* player)
{
    if (GTK_WIDGET_REALIZED (widget))
    {
        if (player->video_state)
        {
            stream_resize_video(player->video_state, event->width, event->height);
        }
        else
        {
            if(player->ffmpeg_initialized)
            {
                stream_resize_video(NULL, event->width, event->height);
            }
        }
    }
        
    return FALSE;    
}

static void
hx_ffmpeg_drawing_area_realize(GtkWidget* widget, HXFFMpegPlayer* player)
{
    int result;    
        
    gtk_widget_set_double_buffered(widget, FALSE);

    gdk_window_set_events(widget->window, GDK_ALL_EVENTS_MASK);    


    /* SDL uses a different X display connection -- XSync here
       so our view of the world matches that on the X server */
    gdk_flush();
    
    /* Hook up SDL & initialize ffmpeg */
    result = stream_init(GDK_DRAWABLE_XDISPLAY(widget->window),
                         GDK_DRAWABLE_XID(widget->window));
    g_return_if_fail(result == 0);

    player->ffmpeg_initialized = TRUE;    
    
    stream_resize_video(player->video_state,
                        widget->allocation.width,
                        widget->allocation.height);

    if(player->timer_id < 0)
    {         
        player->timer_id = gtk_timeout_add(SLEEP_TIME, 
                                           hx_ffmpeg_player_pump, 
                                           player); 
    }     
}

static void
hx_ffmpeg_drawing_area_unrealize(GtkWidget* widget, HXFFMpegPlayer* player)
{
    if(player->timer_id >= 0)
    {
        gtk_timeout_remove(player->timer_id);
    }
    
    player->timer_id = -1;    
}


static void
hx_ffmpeg_player_open_location (HXBasicPlayback* playback,
                                const gchar*     location)
{
    HXFFMpegPlayer* player = NULL;
    const gchar file_spec[] = "file://";
    const gint file_spec_len = sizeof(file_spec) - 1;

    g_return_if_fail(HX_IS_FFMPEG_PLAYER(playback));
        
    player = HX_FFMPEG_PLAYER(playback);

    if(player->ffmpeg_initialized &&
       player->state != FFMPEG_STATE_STOPPED)
    {
        hx_ffmpeg_player_stop(playback);
    }

    g_free(player->filename);
    player->filename = NULL;
    
    if(strncmp(location, file_spec, file_spec_len) == 0)
    {
        /* We only support file:// uri's */
        player->filename = g_strdup(location + file_spec_len);
    }
}

static gchar*
hx_ffmpeg_player_get_opened_location (HXBasicPlayback* playback)
{
    HXFFMpegPlayer* player = NULL;
    gchar* location = NULL;

    g_return_val_if_fail(HX_IS_FFMPEG_PLAYER(playback), NULL);
        
    player = HX_FFMPEG_PLAYER(playback);

    if(player->filename)
    {
        location = g_strdup_printf("file://%s", player->filename);
    }
    
    return location;
}

static GtkWidget*
hx_ffmpeg_player_get_video_area (HXBasicPlayback* playback)
{
    HXFFMpegPlayer* player = NULL;

    g_return_val_if_fail(HX_IS_FFMPEG_PLAYER(playback), NULL);
        
    player = HX_FFMPEG_PLAYER(playback);

    return player->drawing_area;
}

static void
hx_ffmpeg_player_play (HXBasicPlayback* playback)
{
    HXFFMpegPlayer* player = NULL;

    g_return_if_fail(HX_IS_FFMPEG_PLAYER(playback));
        
    player = HX_FFMPEG_PLAYER(playback);

    if(player->state ==  FFMPEG_STATE_STOPPED)
    {
        if(player->filename)
        {
            player->video_state = stream_open(player->filename,
                                              NULL);

            player->state = FFMPEG_STATE_PLAYING;
        }
    }
    else if(player->state == FFMPEG_STATE_PAUSED)
    {
        stream_pause(player->video_state);
        
        player->state = FFMPEG_STATE_PLAYING;
    }

    g_signal_emit_by_name(playback, "play");
    g_signal_emit_by_name(playback, "state_changed");
}

static void
hx_ffmpeg_player_pause (HXBasicPlayback* playback)
{
    HXFFMpegPlayer* player = NULL;

    g_return_if_fail(HX_IS_FFMPEG_PLAYER(playback));
        
    player = HX_FFMPEG_PLAYER(playback);

    if(player->state == FFMPEG_STATE_PLAYING)
    {
        stream_pause(player->video_state);
        player->state = FFMPEG_STATE_PAUSED;
    }

    g_signal_emit_by_name(playback, "pause");
    g_signal_emit_by_name(playback, "state_changed");
}

static void
hx_ffmpeg_player_stop (HXBasicPlayback* playback)
{
    HXFFMpegPlayer* player = NULL;

    g_return_if_fail(HX_IS_FFMPEG_PLAYER(playback));
        
    player = HX_FFMPEG_PLAYER(playback);

    if(player->state != FFMPEG_STATE_STOPPED)
    {
        stream_close(player->video_state);
        player->state = FFMPEG_STATE_STOPPED;
    }

    g_signal_emit_by_name(playback, "stop");
    g_signal_emit_by_name(playback, "state_changed");
}

static void
hx_ffmpeg_player_start_seeking (HXBasicPlayback* playback)
{
    HXFFMpegPlayer* player = NULL;

    g_return_if_fail(HX_IS_FFMPEG_PLAYER(playback));
    
    player = HX_FFMPEG_PLAYER(playback);

    if(player->state == FFMPEG_STATE_PLAYING)
    {
        stream_pause(player->video_state);
        player->state = FFMPEG_STATE_PAUSED;
    }

    player->is_seeking = TRUE;
}

static void
hx_ffmpeg_player_seek (HXBasicPlayback* playback,
                       gint64           position)
{
    HXFFMpegPlayer* player = NULL;

    g_return_if_fail(HX_IS_FFMPEG_PLAYER(playback));
        
    player = HX_FFMPEG_PLAYER(playback);

    stream_seek(player->video_state, position, 0);
}

static void
hx_ffmpeg_player_stop_seeking (HXBasicPlayback* playback)
{
    HXFFMpegPlayer* player = NULL;

    g_return_if_fail(HX_IS_FFMPEG_PLAYER(playback));
        
    player = HX_FFMPEG_PLAYER(playback);

    if(player->state == FFMPEG_STATE_PAUSED)
    {
        stream_pause(player->video_state);
        player->state = FFMPEG_STATE_PLAYING;
    }    

    player->is_seeking = FALSE;
}

static gboolean
hx_ffmpeg_player_is_playing (HXBasicPlayback* playback)
{
    HXFFMpegPlayer* player = NULL;

    g_return_val_if_fail(HX_IS_FFMPEG_PLAYER(playback), FALSE);
        
    player = HX_FFMPEG_PLAYER(playback);

    return (player->state == FFMPEG_STATE_PLAYING);
}

static gboolean
hx_ffmpeg_player_is_paused (HXBasicPlayback* playback)
{
    HXFFMpegPlayer* player = NULL;

    g_return_val_if_fail(HX_IS_FFMPEG_PLAYER(playback), FALSE);
        
    player = HX_FFMPEG_PLAYER(playback);

    return (player->state == FFMPEG_STATE_PAUSED);
}

static gboolean
hx_ffmpeg_player_is_stopped (HXBasicPlayback* playback)
{
    HXFFMpegPlayer* player = NULL;

    g_return_val_if_fail(HX_IS_FFMPEG_PLAYER(playback), FALSE);
        
    player = HX_FFMPEG_PLAYER(playback);

    return (player->state == FFMPEG_STATE_STOPPED);
}

static gboolean
hx_ffmpeg_player_is_seeking (HXBasicPlayback* playback)
{
    HXFFMpegPlayer* player = NULL;

    g_return_val_if_fail(HX_IS_FFMPEG_PLAYER(playback), FALSE);
        
    player = HX_FFMPEG_PLAYER(playback);

    return (player->is_seeking);
}

static gboolean
hx_ffmpeg_player_can_play (HXBasicPlayback* playback)
{
    HXFFMpegPlayer* player = NULL;

    g_return_val_if_fail(HX_IS_FFMPEG_PLAYER(playback), FALSE);
        
    player = HX_FFMPEG_PLAYER(playback);

    return (player->state == FFMPEG_STATE_PLAYING) ||
           (player->state == FFMPEG_STATE_PAUSED);
}

static gboolean
hx_ffmpeg_player_can_pause (HXBasicPlayback* playback)
{
    HXFFMpegPlayer* player = NULL;

    g_return_val_if_fail(HX_IS_FFMPEG_PLAYER(playback), FALSE);
        
    player = HX_FFMPEG_PLAYER(playback);

    return (player->state == FFMPEG_STATE_PLAYING);
}

static gboolean
hx_ffmpeg_player_can_stop (HXBasicPlayback* playback)
{
    HXFFMpegPlayer* player = NULL;

    g_return_val_if_fail(HX_IS_FFMPEG_PLAYER(playback), FALSE);
        
    player = HX_FFMPEG_PLAYER(playback);

    return (player->state == FFMPEG_STATE_PLAYING) ||
           (player->state == FFMPEG_STATE_STOPPED);
}

static gboolean
hx_ffmpeg_player_can_seek (HXBasicPlayback* playback)
{
    HXFFMpegPlayer* player = NULL;

    g_return_val_if_fail(HX_IS_FFMPEG_PLAYER(playback), FALSE);
        
    player = HX_FFMPEG_PLAYER(playback);

    return ((player->state == FFMPEG_STATE_PLAYING) ||
            (player->state == FFMPEG_STATE_PAUSED)) &&
           !player->is_seeking;
}

static gboolean
hx_ffmpeg_player_get_current_clip_basic_metadata (HXBasicPlayback*    playback,
                                                  HXBasicMetadataType metadata,
                                                  GValue*             value)
{
    HXFFMpegPlayer* player = NULL;

    g_return_val_if_fail(HX_IS_FFMPEG_PLAYER(playback), FALSE);
        
    player = HX_FFMPEG_PLAYER(playback);

    (void) player;

    // no metadata retrival support.
    
    return FALSE;
}

static gint64
hx_ffmpeg_player_get_length (HXBasicPlayback* playback)
{
    HXFFMpegPlayer* player = NULL;

    g_return_val_if_fail(HX_IS_FFMPEG_PLAYER(playback), 0);
        
    player = HX_FFMPEG_PLAYER(playback);

    (void) player;
    
    return 0;
}

static gint64
hx_ffmpeg_player_get_position (HXBasicPlayback* playback)
{
    HXFFMpegPlayer* player = NULL;

    g_return_val_if_fail(HX_IS_FFMPEG_PLAYER(playback), 0);
        
    player = HX_FFMPEG_PLAYER(playback);

    (void) player;
    
    return 0;
}

static gboolean
hx_ffmpeg_player_is_live (HXBasicPlayback* playback)
{
    HXFFMpegPlayer* player = NULL;

    g_return_val_if_fail(HX_IS_FFMPEG_PLAYER(playback), FALSE);
        
    player = HX_FFMPEG_PLAYER(playback);

    (void) player;
    
    return FALSE;
}

static gboolean
hx_ffmpeg_player_is_infinite_duration (HXBasicPlayback* playback)
{
    HXFFMpegPlayer* player = NULL;

    g_return_val_if_fail(HX_IS_FFMPEG_PLAYER(playback), FALSE);
        
    player = HX_FFMPEG_PLAYER(playback);

    /* Pretend we're infinite until we figure out duration & position */
    return TRUE;
}

static gboolean
hx_ffmpeg_player_can_set_volume (HXBasicPlayback* playback)
{
    HXFFMpegPlayer* player = NULL;

    g_return_val_if_fail(HX_IS_FFMPEG_PLAYER(playback), FALSE);
        
    player = HX_FFMPEG_PLAYER(playback);

    (void) player;
    
    return FALSE;
}

static gboolean
hx_ffmpeg_player_can_set_mute (HXBasicPlayback* playback)
{
    HXFFMpegPlayer* player = NULL;

    g_return_val_if_fail(HX_IS_FFMPEG_PLAYER(playback), FALSE);
        
    player = HX_FFMPEG_PLAYER(playback);

    (void) player;

    return FALSE;
}
    
static void
hx_ffmpeg_player_set_volume_percent (HXBasicPlayback* playback,
                                     gint             volume)
{
    HXFFMpegPlayer* player = NULL;

    g_return_if_fail(HX_IS_FFMPEG_PLAYER(playback));
        
    player = HX_FFMPEG_PLAYER(playback);

    (void) player;
}

static gint
hx_ffmpeg_player_get_volume_percent (HXBasicPlayback* playback)
{
    HXFFMpegPlayer* player = NULL;

    g_return_val_if_fail(HX_IS_FFMPEG_PLAYER(playback), 0);
        
    player = HX_FFMPEG_PLAYER(playback);

    (void) player;

    return 0;
}

static void
hx_ffmpeg_player_set_mute (HXBasicPlayback* playback,
                           gboolean         mute)
{
    HXFFMpegPlayer* player = NULL;

    g_return_if_fail(HX_IS_FFMPEG_PLAYER(playback));
        
    player = HX_FFMPEG_PLAYER(playback);

    (void) player;
}

static gboolean
hx_ffmpeg_player_get_mute (HXBasicPlayback* playback)
{
    HXFFMpegPlayer* player = NULL;

    g_return_val_if_fail(HX_IS_FFMPEG_PLAYER(playback), FALSE);
        
    player = HX_FFMPEG_PLAYER(playback);

    (void) player;

    return FALSE;
}

static void
hx_ffmpeg_player_get_ideal_visual_content_size (HXBasicPlayback* playback,
                                                gint*            width,
                                                gint*            height)
{
    HXFFMpegPlayer* player = NULL;

    g_return_if_fail(HX_IS_FFMPEG_PLAYER(playback));
        
    player = HX_FFMPEG_PLAYER(playback);

    *width = 320;
    *height = 200;
}

static gboolean
hx_ffmpeg_player_has_visual_content (HXBasicPlayback* playback)
{
    HXFFMpegPlayer* player = NULL;

    g_return_val_if_fail(HX_IS_FFMPEG_PLAYER(playback), FALSE);
        
    player = HX_FFMPEG_PLAYER(playback);
    
    return TRUE;
}


--- NEW FILE: hxffmpegfactory.c ---
/* ***** BEGIN LICENSE BLOCK *****
 * Source last modified: $Id: hxffmpegfactory.c,v 1.1 2005/07/16 00:43:37 rggammon Exp $
 * 
 * Portions Copyright (c) 1995-2005 RealNetworks, Inc. All Rights Reserved.
 * 
 * The contents of this file, and the files included with this file,
 * are subject to the current version of the RealNetworks Public
 * Source License (the "RPSL") available at
 * http://www.helixcommunity.org/content/rpsl unless you have licensed
 * the file under the current version of the RealNetworks Community
 * Source License (the "RCSL") available at
 * http://www.helixcommunity.org/content/rcsl, in which case the RCSL
 * will apply. You may also obtain the license terms directly from
 * RealNetworks.  You may not use this file except in compliance with
 * the RPSL or, if you have a valid RCSL with RealNetworks applicable
 * to this file, the RCSL.  Please see the applicable RPSL or RCSL for
 * the rights, obligations and limitations governing use of the
 * contents of the file.
 * 
 * Alternatively, the contents of this file may be used under the
 * terms of the GNU Lesser General Public License Version 2 or later
 * (the "LGPL") in which case the provisions of the LGPL are applicable
 * instead of those above. If you wish to allow use of your version of
 * this file only under the terms of the LGPL, and not to allow others
 * to use your version of this file under the terms of either the RPSL
 * or RCSL, indicate your decision by deleting the provisions above
 * and replace them with the notice and other provisions required by
 * the LGPL. If you do not delete the provisions above, a recipient may
 * use your version of this file under the terms of any one of the
 * RPSL, the RCSL or the LGPL.
 * 
 * This file is part of the Helix DNA Technology. RealNetworks is the
 * developer of the Original Code and owns the copyrights in the
 * portions it created.
 * 
 * This file, and the files included with this file, is distributed
 * and made available on an 'AS IS' basis, WITHOUT WARRANTY OF ANY
 * KIND, EITHER EXPRESS OR IMPLIED, AND REALNETWORKS HEREBY DISCLAIMS
 * ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES
 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET
 * ENJOYMENT OR NON-INFRINGEMENT.
 * 
 * Technology Compatibility Kit Test Suite(s) Location:
 *    http://www.helixcommunity.org/content/tck
 * 
 * Contributor(s):
 * 
 * ***** END LICENSE BLOCK ***** */

/* This backend uses gtk and glib for easy XEmbed and
   dbus support. One could potentially eliminate these
   dependancies by supporting XEmbed and dbus directly. */

#include <X11/Xlib.h>

#include <gtk/gtk.h>
#include <dbus/dbus-glib.h>
#include <stdlib.h>

#include "hxffmpegplayer.h"
#include "hxdbusremoteplayerfactory.h"
#include "hxbasicplayback.h"

static HXBasicPlayback*
create_player(GdkNativeWindow socket_id,
              const gchar* license)
{

    (void) socket_id;
    HXBasicPlayback* playback = NULL;
    HXFFMpegPlayer* player = hx_ffmpeg_player_new(license);

    if(player)
    {
        playback = HX_BASIC_PLAYBACK(player);
    }
    
    return playback;
}

int main(int argc, char* argv[])
{
    HXDBusRemotePlayerFactory* factory = NULL;

    XInitThreads();
    
    if(!gtk_init_check(&argc, &argv))
    {
        /* g_error will call abort */
	g_error("Unable to initialize gtk");
        return EXIT_FAILURE;
    }

    factory = hx_dbus_remote_player_factory_new("FFMpeg",
                                                create_player);

    if(!factory)
    {
        return EXIT_FAILURE;
    }
    
    gtk_main();

    return EXIT_SUCCESS;
}




More information about the Player-cvs mailing list
 

Site Map   |   Terms of Use   |   Privacy Policy   |   Contact Us

Copyright © 1995-2007 RealNetworks, Inc. All rights reserved. RealNetworks and Helix are trademarks of RealNetworks.
All other trademarks or registered trademarks are the property of their respective holders.