paragui-cvs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[paragui-cvs] CVS: paragui/plugins/mpeg Makefile,NONE,1.1.2.1 pgmpeg-tes


From: Teunis Peters <address@hidden>
Subject: [paragui-cvs] CVS: paragui/plugins/mpeg Makefile,NONE,1.1.2.1 pgmpeg-test.cc,NONE,1.1.2.1 pgmpeg2.cc,NONE,1.1.2.1 pgmpeg2.hh,NONE,1.1.2.1
Date: Mon, 04 Nov 2002 06:12:53 -0500

Update of /cvsroot/paragui/paragui/plugins/mpeg
In directory subversions:/tmp/cvs-serv17456/plugins/mpeg

Added Files:
      Tag: devel-opengl
        Makefile pgmpeg-test.cc pgmpeg2.cc pgmpeg2.hh 
Log Message:
Starting work on MPEG plugin
needs proper merging in with autoconf/automake and the plugin API still needs 
work but at this moment this works :)


--- NEW FILE ---
CFLAGS  = -g -Werror -Wall -mcpu=i686
CFLAGS += -D__USE_STL__ -DGCC3 -D_REENTRANT -DNDEBUG -D_GNU_SOURCE -DHAVE_OPENGL
CFLAGS += -I/usr/include/ptlib/unix
CFLAGS += -I/usr/include/pwlib
CFLAGS += -I/usr/include/openh323 -I/usr/include/crypto -I/usr/X11R6/include
CFLAGS += $(shell paragui2-config --cflags)
CFLAGS += $(shell smpeg-config --cflags)

LDFLAGS = -g -O3
LDLIBS  = -lopenh323 -lpt -ldl -lpthread -lssl -lcrypto
LDLIBS += $(shell paragui2-config --libs)
LDLIBS += $(shell smpeg-config --libs)
LDLIBS += -L/usr/X11R6/lib -lGL -lm
# electricfence debugger
# LDLIBS += -lefence

all: pgmpeg-test

pgmpeg-test: pgmpeg-test.o pgmpeg2.o
        g++ $(LDFLAGS) -o $@ $^ $(LDLIBS)

clean::
        rm -f $(OBJECTS)

%.o: %.c
        gcc $(CFLAGS) -c $< -o $@

%.o: %.cc
        g++ $(CFLAGS) -c $< -o $@

pgmpeg2.o: pgmpeg2.hh

pgmpeg-test.o: pgmpeg2.hh

--- NEW FILE ---
#include "pgmpeg2.hh"
#include "pgbutton.h"
#include "pgwindow.h"
#include "pgslider.h"
#include "pgcheckbutton.h"

#include "pgnavigator.h"
#include "pgdraw.h"

class PG_MyMPEGPlayerWindow : public PG_MoveableMPEGPLayerWindow {
        bool bhasmoved, binclick, bfs;
        PG_Rect wsize;
public:
        PG_MyMPEGPlayerWindow(char *file, PG_Widget *parent, const PG_Rect & r)
          : PG_MoveableMPEGPLayerWindow(file, parent, r) {
          bhasmoved = false;
          binclick  = false;
          bfs       = false;
          wsize = r;
        };

        ~PG_MyMPEGPlayerWindow() { };

protected:
        bool eventMouseButtonDown(const SDL_MouseButtonEvent *button) {
          if (!binclick)
            {
              bhasmoved = false;
              fprintf(stderr, "%s:%s:%i\n", __FILE__, __FUNCTION__, __LINE__);
              return PG_MoveableMPEGPLayerWindow::eventMouseButtonDown(button);
            };
          if (bhasmoved)
            {
              binclick = false;
              fprintf(stderr, "%s:%s:%i\n", __FILE__, __FUNCTION__, __LINE__);
              return PG_MoveableMPEGPLayerWindow::eventMouseButtonDown(button);
            };
          // PG_MoveableMPEGPLayerWindow::eventMouseButtonUp(button);
          return true;
        }
  
        bool eventMouseButtonUp(const SDL_MouseButtonEvent *button) {
          if (bhasmoved)
            {
              fprintf(stderr, "%s:%s:%i\n", __FILE__, __FUNCTION__, __LINE__);
              binclick = false;
              return PG_MoveableMPEGPLayerWindow::eventMouseButtonUp(button);
            };
          if (!binclick)
            {
              fprintf(stderr, "%s:%s:%i\n", __FILE__, __FUNCTION__, __LINE__);
              binclick = true;
              return PG_MoveableMPEGPLayerWindow::eventMouseButtonUp(button);
            };
          PG_Widget* par;
          par = GetParent();
          bfs = !bfs;
          bhasmoved = false;
          binclick = false;
          if (!bfs)
            {
              fprintf(stderr, "%s:%s:%i %i,%i\n", __FILE__, __FUNCTION__, 
__LINE__, wsize.w, wsize.h);
              SizeWidget(wsize.w, wsize.h);
              fprintf(stderr, "%s:%s:%i %i,%i\n", __FILE__, __FUNCTION__, 
__LINE__, wsize.x, wsize.y);
              MoveWidget(wsize.x, wsize.y);
              fprintf(stderr, "%s:%s:%i\n", __FILE__, __FUNCTION__, __LINE__);
            }
          else
            {
              fprintf(stderr, "%s:%s:%i\n", __FILE__, __FUNCTION__, __LINE__);
              wsize.x = this->x;
              wsize.y = this->y;
              wsize.h = this->h;
              wsize.w = this->w;
              if (par != NULL)
                {
                  par->Hide();
                  fprintf(stderr, "%s:%s:%i\n", __FILE__, __FUNCTION__, 
__LINE__);
                  MoveWidget(par->x, par->y);
                  fprintf(stderr, "%s:%s:%i\n", __FILE__, __FUNCTION__, 
__LINE__);
                  SizeWidget(par->w, par->h);
                  fprintf(stderr, "%s:%s:%i\n", __FILE__, __FUNCTION__, 
__LINE__);
                  // UpdateScreen();
                  // fprintf(stderr, "%s:%s:%i\n", __FILE__, __FUNCTION__, 
__LINE__);
                  par->Show();
                }
              else
                {
                  fprintf(stderr, "%s:%s:%i\n", __FILE__, __FUNCTION__, 
__LINE__);
                  MoveWidget(0, 0);
                  fprintf(stderr, "%s:%s:%i\n", __FILE__, __FUNCTION__, 
__LINE__);
                  SizeWidget(PG_Application::GetScreenWidth(),
                             PG_Application::GetScreenHeight());
                  fprintf(stderr, "%s:%s:%i\n", __FILE__, __FUNCTION__, 
__LINE__);
                };
              fprintf(stderr, "%s:%s:%i\n", __FILE__, __FUNCTION__, __LINE__);
              return true;
            };
          fprintf(stderr, "%s:%s:%i\n", __FILE__, __FUNCTION__, __LINE__);
          return true;
        }
  
        bool eventMouseMotion (const SDL_MouseMotionEvent *motion) {
          /* if ((abs(motion->x) > 5) && (abs(motion->y) > 5))
                { bhasmoved=true; return 
PG_MoveableMPEGPlayerWindow::eventMouseMotion(motion); };
          */
          if (binclick) { fprintf(stderr, "%s:%s:%i\n", __FILE__, __FUNCTION__, 
__LINE__); };
          bhasmoved = true;
          return PG_MoveableMPEGPLayerWindow::eventMouseMotion(motion);
        }
};

// int done = 0;
bool handle_exit(PG_Button* button, PG_Pointer* clientdata)
{
        PG_Application* app = reinterpret_cast<PG_Application*>(clientdata);
        app->Quit();
        // done = 1;
        return true;
}

class PG_Panel : public PG_ThemeWidget
{
public:
        PG_Panel(PG_Widget* parent, const PG_Rect& r) 
          : PG_ThemeWidget(parent, r) 
        {
                SetBorderSize(2);
        };

};

class PG_PlayerWindow : public PG_Window
{
private:
  bool my_resizeMode;
  Uint8 my_resizeTransparency;
  PG_Point my_resizeDelta;
public:
  PG_MPEGPlayerWindow *player;

  PG_PlayerWindow(PG_Widget* parent, const PG_Rect& r,
                  const char* windowtext,
                  Uint32 flags = WF_DEFAULT,
                  const char* style="Window", int heightTitlebar = 25)
    : PG_Window(parent,r,windowtext,flags,style,heightTitlebar)
  {
    player = new PG_MPEGPlayerWindow(windowtext, this, 
PG_Rect(2,27,r.w-4,r.h-29));
    player->Show();
    my_resizeMode = false;
  };
protected:
#if 0
  void eventSizeWidget(Uint16 w, Uint16 h)
  {
    PG_Window::eventSizeWidget(w,h);
    player->eventSizeWidget(w-4,h-29);
  }
#endif
  bool eventMouseButtonDown(const SDL_MouseButtonEvent *button)
  {
    PG_Rect ta;
    ta.x = this->x + (this->w - 2);
    ta.y = this->y + (this->h - 2);
    ta.w = 2;
    ta.h = 2;
    
    int x,y;
    x = button->x;
    y = button->y;

    if ((ta.x <= x) && (x <= ta.x+ta.w))
      {
        if ((ta.y <= y) && (y <= ta.y + ta.h))
          {
            my_resizeMode = true;
            my_resizeDelta.x = ta.x - x;
            my_resizeDelta.y = ta.y - y;
            Show();
            SetCapture();
            return true;
          };
      }
    
    Show();
    return PG_Window::eventMouseButtonDown(button);
  }
  
  bool eventMouseButtonUp(const SDL_MouseButtonEvent *button)
  {
#if 0
    int x,y;
    
    x = button->x;
    y = button->y;
    
    x += my_resizeDelta.x;
    y += my_resizeDelta.y;
    
    if (x < 0) x=0;
    if (y < 0) y=0;
    if (x > (my_srfScreen->GetWidth() - my_width - 1))
      x = (my_srfScreen->GetWidth() - my_width - 1);
    if (y > (my_srfScreen->GetHeight() - my_height - 1))
      y = (my_srfScreen->GetHeight() - my_height -1);
#endif
    if (my_resizeMode)
      {
        my_resizeMode = false;
        ReleaseCapture();
        return true;
      }
    return PG_Window::eventMouseButtonUp(button);
  }
  
  bool eventMouseMotion (const SDL_MouseMotionEvent *motion)
  {
    if(!my_resizeMode) {
      return PG_Window::eventMouseMotion(motion);
    }
    int x,y;
    x = motion->x;
    y = motion->y;
    
    x += my_resizeDelta.x;
    y += my_resizeDelta.y;
    
    if (GetParent() != NULL)  // Not a top-level-widget
      {
        PG_Point pos = GetParent()->ScreenToClient(x,y);
        x = pos.x;
        y = pos.y;         // Should not be moved out of the parent:
        if (x >= GetParent()->Width() - 5) x = GetParent()->Width() - 5;
        if (y >= GetParent()->Height() - 5) y = GetParent()->Height() - 5;
      }
    else                      // A top-level-widget
      {
        if (x > (int)(my_srfScreen->GetWidth() - 1)) x = 
(my_srfScreen->GetWidth() - 1);
        if (y > (int)(my_srfScreen->GetHeight() - 1)) y = 
(my_srfScreen->GetHeight() - 1);
      }
    x -= this->x;
    y -= this->y;
    if (x < 16)    x=16;
    if (y < 16+25) y=16+25;

    SizeWidget(x, y);
    player->SizeWidget(w-4,h-29);
    return true;
  }
};

class MyApplication : public PG_Application, public PG_Navigator {
protected:
        bool isalt;
public:
        MyApplication() : PG_Application(), PG_Navigator() { isalt=false; };
protected:
        bool eventKeyDown(const SDL_KeyboardEvent* key);
};

bool MyApplication::eventKeyDown(const SDL_KeyboardEvent* key) {
        PG_Widget* dest = NULL;

        switch(key->keysym.sym) {
                case SDLK_RALT:
                case SDLK_LALT:
                  isalt=true;
                  break;
                case SDLK_RETURN:
                  if (isalt)
                    {
                      isalt = false;
                      SDL_WM_ToggleFullScreen(GetScreen()->SDL());
                    };
                  break;
                case SDLK_UP:
                        dest = FindUp();
                        break;
                case SDLK_DOWN:
                        dest = FindDown();
                        break;
                case SDLK_LEFT:
                        dest = FindLeft();
                        break;
                case SDLK_RIGHT:
                        dest = FindRight();
                        break;
                case SDLK_TAB:
                        dest = GotoNext();
                        if(dest == NULL) {
                                GotoFirst();
                        }
                        return true;
                case SDLK_SPACE:
                        Action(PG_ACT_OK);
                        return true;
                default:
                        dest = NULL;
                        break;
        }

        if(dest != NULL) {
                Goto(dest);
                return true;
        }

        return false;
}

int main(int argc, char* argv[]) 
{
        if (argc != 2){
                printf("Use: %s archivo_mpeg\n", argv[0]);
                return -1;
        }

        // Uint32 flags = SDL_SWSURFACE;// | SDL_FULLSCREEN;
        // Uint32 flags = SDL_HWSURFACE;// | SDL_FULLSCREEN;
        Uint32 flags = 0;
        int bpp = 0;
        // PG_Application app;
        MyApplication app;
        /* flags |= SDL_RESIZABLE */ /* need hooks to make this useful */

        if(!app.LoadTheme("default")) {
                printf("Unable to load theme!\n");
                exit(-1);
        }

        if(!app.InitScreen(800, 600 , bpp, flags)){
                printf("Resolution not supported\n");
                exit(-1);
        }

        PG_Panel f(NULL, PG_Rect(700, 0, 100, 600));
        f.Show();

        int ypos = 10, height = 30, yskip = 5;

        PG_Button start(&f, 12, PG_Rect(10,ypos,80,height), "Start");
        start.Show();
        ypos += height + yskip;
        
        PG_Button stop(&f, 13, PG_Rect(10,ypos,80,height), "Stop");
        stop.Show();
        ypos += height + yskip;
        
        PG_Button rewind(&f, 14, PG_Rect(10,ypos,80,height), "Rewind");
        rewind.Show();
        ypos += height + yskip;
        
        PG_Button pause(&f, 15, PG_Rect(10,ypos,80,height), "Pause");
        pause.Show();
        ypos += height + yskip;
        
        PG_Button quit(&f, 16, PG_Rect(10,ypos,80,height), "Quit");
        quit.sigButtonClick.connect(slot(handle_exit), &app);
        quit.Show();
        ypos += height + yskip;

        PG_MPEGPlayerWindow *thePlayer;
#if 0
#define CMPEG PG_MPEGPlayerWindow
        // #define CMPEG PG_MoveableMPEGPLayerWindow
        // #define CMPEG PG_MyMPEGPlayerWindow
#if 0
        thePlayer = new CMPEG(argv[1], NULL, PG_Rect(100, 100, 640, 480));
#else
        PG_Panel fq(NULL, PG_Rect(0, 0, 700, 600-23));
        fq.Show();
        thePlayer = new CMPEG(argv[1], &fq, PG_Rect(100, 100, 640, 480));
#endif
#else
        PG_PlayerWindow vid(NULL, PG_Rect(100, 100, 640+4, 480+29), argv[1]);
        thePlayer = vid.player;
        vid.Show();
#endif
        thePlayer->SetTransparency(128);
        thePlayer->Show();

        PG_Slider vslider(NULL, -1, PG_Rect(10,600-22,700-22,20), 
PG_SB_HORIZONTAL);
        thePlayer->handle_position(&vslider);
        vslider.sigSlide.connect(slot(*thePlayer, 
&PG_MPEGPlayerWindow::handle_reposition));
        vslider.Show();

        PG_Window win(NULL, PG_Rect(200,150,200,150), "Overlap Window");
        PG_Label label(&win, PG_Rect(10,40,180,20), "Transparency");
        label.SetAlignment(PG_TA_CENTER);
        PG_Slider slider(&win, -1, PG_Rect(10,65,180,20), PG_SB_HORIZONTAL);
        slider.SetRange(0, 255);
        slider.SetPosition(128);                

        PG_CheckButton check(&win, -1, PG_Rect(10,90,180,20), "fast 
displaymode");

        start.sigButtonClick.connect(slot(*thePlayer, 
&PG_MPEGPlayerWindow::handle_start));
        stop.sigButtonClick.connect(slot(*thePlayer, 
&PG_MPEGPlayerWindow::handle_stop));
        rewind.sigButtonClick.connect(slot(*thePlayer, 
&PG_MPEGPlayerWindow::handle_rewind));
        pause.sigButtonClick.connect(slot(*thePlayer, 
&PG_MPEGPlayerWindow::handle_pause));
        slider.sigSlide.connect(slot(*thePlayer, 
&PG_MPEGPlayerWindow::handle_transparency));
        check.sigButtonClick.connect(slot(*thePlayer, 
&PG_MPEGPlayerWindow::handle_fastmode));
        
        win.SetTransparency(128);
        win.Show();

        app.Add(&start);
        app.Add(&stop);
        app.Add(&rewind);
        app.Add(&pause);
        app.Add(&quit);
        // app.Add(&slider);
        // app.Add(&vslider);
        app.GotoFirst();

        // thePlayer->SendToBack();
        app.Run();
        return EXIT_SUCCESS;
}

--- NEW FILE ---
/* pgmpeg2.cc
 * ----------
    PGMPEG - MPEG1 player library for ParaGUI
    Copyright (C) 2002  Eric Ross, Alexander Pipelka, Teunis Peters

    This library is free software; you can redistribute it and/or
    modify it under the terms of the GNU Library 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
    Library General Public License for more details.

    You should have received a copy of the GNU Library General Public
    License along with this library; if not, write to the Free
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA

    Eric Ross <address@hidden>
    Alexander Pipelka <address@hidden>
    Teunis Peters <address@hidden>
 */

#include "pgmpeg2.hh"
#include "pgdraw.h"

/* entirely arbitrary.  Probably smarter to make it a variable inside the class
   or something like that */
#define PLAYERSCALE 1000

/* notes from Teunis Peters:
 * it might be an idea to move the 'frameupdate' function into the functions
 * Play(), ...
 * but I haven't yet seen the point - the current method makes a little more
 * sense from the perspective that the PG_MPEGPlayer doesn't know about the
 * widgets.
 */

void PG_MPEGPlayerWindow::handle_position(PG_Slider* slider) {
  pos = slider;
  if (pos == NULL) return;
  double v = currenttime() / totaltime();
  pos->SetRange(0,PLAYERSCALE);
  pos->SetPosition(v * PLAYERSCALE);
};

bool PG_MPEGPlayerWindow::handle_start(PG_Button* button) {
  // int id = button->GetID();
  Play();
  frameupdate();
  return true;
};

bool PG_MPEGPlayerWindow::handle_stop(PG_Button* button) {
  Stop();
  frameupdate();
  return true;
};

bool PG_MPEGPlayerWindow::handle_rewind(PG_Button* button) {
  SMPEGstatus v = cstat();
  Rewind();
  if (v == SMPEG_PLAYING) Play();
  frameupdate();
  return true;
};

bool PG_MPEGPlayerWindow::handle_pause(PG_Button* button) {
  Pause();
  frameupdate();
  return true;
};

bool PG_MPEGPlayerWindow::handle_transparency(PG_Slider* slider, long data) {
  SetTransparency(data);
  Update();
  return true;
}

bool PG_MPEGPlayerWindow::handle_fastmode(PG_RadioButton* button) {
  SetFastMode(button->GetPressed());
  return true;
}

bool PG_MPEGPlayerWindow::handle_reposition(PG_Slider* slider, long data) {
  SMPEGstatus v = cstat();
  double setp;
  setp = ((double)(data - slider->GetMinRange()) /
          (double)(slider->GetMaxRange() - slider->GetMinRange()));
  if (v == SMPEG_PLAYING) Stop();
  Seek(setp * totalsize());
  if (v == SMPEG_PLAYING) Play();
  return true;
};

void PG_MPEGPlayerWindow::frameupdate() {
  PG_MPEGPlayer::frameupdate();
  if (pos != NULL) {
    double v = currenttime() / totaltime();
    pos->SetPosition(v * PLAYERSCALE);
  };
};

std::map<SDL_Surface*, PG_MPEGPlayer *> PG_MPEGPlayer::hash;

PG_MPEGPlayer::PG_MPEGPlayer(const char *file, PG_Widget* parent, const 
PG_Rect& rect) 
  : PG_Widget(parent, rect, true) {
  SetDirtyUpdate(true);
  f = SMPEG_new(file, &info, true);
  SMPEG_setdisplay(f, my_srfObject->SDL(), NULL, cb);
  hash[my_srfObject->SDL()] = this;
  currentscreen = my_srfObject->SDL();
  bFastMode = false;
}

void PG_MPEGPlayer::Play(void)   { SMPEG_play(f);   };
void PG_MPEGPlayer::Stop(void)   { SMPEG_stop(f);   };
void PG_MPEGPlayer::Rewind(void) { SMPEG_rewind(f); };
void PG_MPEGPlayer::Pause(void)  { SMPEG_pause(f);  };
void PG_MPEGPlayer::Seek(int bytes) { SMPEG_seek(f, bytes); };
void PG_MPEGPlayer::Skip(float seconds) { SMPEG_skip(f, seconds); };

PG_MPEGPlayer::~PG_MPEGPlayer() {
  Stop();
  SMPEG_delete(f);
  hash.erase(my_srfObject->SDL());
}

void PG_MPEGPlayer::cb(SDL_Surface* dst, int x, int y, unsigned int w, unsigned 
int h) {
  PG_Rect rsrc;
  PG_Rect rdst;
  
  PG_Application::LockScreen();
  PG_MPEGPlayer *player = hash[dst];
  if(player->bFastMode) {
    rsrc.SetRect(x, y, w, h);
    rdst = *(player->GetClipRect());
    player->my_srfScreen->BlitSurface(dst, rsrc, rdst);
    player->my_srfScreen->UpdateRects(1, &rdst);
  }
  else {
    player->Update();
  }
  player->frameupdate();
  
  PG_Application::UnlockScreen();               
}

void PG_MPEGPlayer::frameupdate() { SMPEG_getinfo(f, &info); };
void PG_MPEGPlayer::SetFastMode(bool fast) { bFastMode = fast; }

void PG_MPEGPlayer::eventSizeWidget(Uint16 w, Uint16 h)
{
  fprintf(stderr, "%s:%s:%i\n", __FILE__, __FUNCTION__, __LINE__);
  PG_Widget::eventSizeWidget(w,h);
#if 0
  fprintf(stderr, "%s:%s:%i\n", __FILE__, __FUNCTION__, __LINE__);
  SMPEGstatus v = cstat();
  if (v == SMPEG_PLAYING) Stop();
  fprintf(stderr, "%s:%s:%i\n", __FILE__, __FUNCTION__, __LINE__);
  SMPEG_setdisplay(f, my_srfObject, NULL, cb);
  fprintf(stderr, "%s:%s:%i\n", __FILE__, __FUNCTION__, __LINE__);
  hash[my_srfObject->SDL()] = this;
  fprintf(stderr, "%s:%s:%i\n", __FILE__, __FUNCTION__, __LINE__);
  SMPEG_scaleXY(f,w,h);
  fprintf(stderr, "%s:%s:%i\n", __FILE__, __FUNCTION__, __LINE__);
  if (v == SMPEG_PLAYING) Play();
#endif
};

bool PG_MPEGPlayer::SizeWidget(Uint16 w, Uint16 h)
{
  fprintf(stderr, "%s:%s:%i %i,%i\n", __FILE__, __FUNCTION__, __LINE__, w, h);
  bool rv = PG_Widget::SizeWidget(w,h);
  fprintf(stderr, "%s:%s:%i\n", __FILE__, __FUNCTION__, __LINE__);
  // if (rv)
    {
      SMPEGstatus v = cstat();
      fprintf(stderr, "%s:%s:%i\n", __FILE__, __FUNCTION__, __LINE__);
      if (v == SMPEG_PLAYING) Pause();
      // screen = SDL_SetVideoMode(event.resize.w, event.resize.h, 
screen->format->BitsPerPixel, screen->flags);
      fprintf(stderr, "%s:%s:%i\n", __FILE__, __FUNCTION__, __LINE__);
      if (my_srfObject->SDL() != currentscreen)
        {
          fprintf(stderr, "%s:%s:%i\n", __FILE__, __FUNCTION__, __LINE__);
          hash.erase(currentscreen);
          currentscreen = my_srfObject->SDL();
          hash[my_srfObject->SDL()] = this;
          SMPEG_setdisplay(f, my_srfObject->SDL(), NULL, cb);
        };
      fprintf(stderr, "%s:%s:%i\n", __FILE__, __FUNCTION__, __LINE__);
      SMPEG_scaleXY(f, my_srfObject->GetWidth(), my_srfObject->GetHeight());
      fprintf(stderr, "%s:%s:%i\n", __FILE__, __FUNCTION__, __LINE__);
      if (v == SMPEG_PLAYING) SMPEG_pause(f);
      fprintf(stderr, "%s:%s:%i\n", __FILE__, __FUNCTION__, __LINE__);
    };
  return rv;
};

--- NEW FILE ---
/* pgmpeg2.hh
 * ----------
    PGMPEG - MPEG1 player library for ParaGUI
    Copyright (C) 2002  Eric Ross, Alexander Pipelka, Teunis Peters

    This library is free software; you can redistribute it and/or
    modify it under the terms of the GNU Library 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
    Library General Public License for more details.

    You should have received a copy of the GNU Library General Public
    License along with this library; if not, write to the Free
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA

    Eric Ross <address@hidden>
    Alexander Pipelka <address@hidden>
    Teunis Peters <address@hidden>
 */

#ifndef PGMPEG2_HH
#define PGMPEG2_HH

#include "pgapplication.h"
#include "pgwidget.h"
#include "pgbutton.h"
#include "pgwindow.h"
#include "pgslider.h"
#include "pgcheckbutton.h"

#include "smpeg/MPEG.h"
#include "smpeg/MPEGfilter.h"
#include "smpeg/smpeg.h"

#include <map>

/**
    @author Eric Ross, Alexander Pipelka, Teunis Peters
    
    @short A widget to display MPEG1 streams
    
    This widget displays MPEG1 video streams. It behaves exactly
    like other widgets except that you see the videostream inside ;-)
    The widget can be embedded into others and overlapping is fully
    supported.
*/

class PG_MPEGPlayer : public PG_Widget {
public:
        /**
        Constructor of the MPEG player
        @param file     path to videostream
        @param parent   pointer to parent widget
        @param rect     position of the widget
        
        Every PG_MPEGPlayer object constructs an associated MPEG (smpeg)
        object internally.
        */
        PG_MPEGPlayer(const char *file, PG_Widget* parent, const PG_Rect& rect);

        /**
        Destruct the widget
        
        Cleans up the widget and deletes the internally created MPEG object
        */
        ~PG_MPEGPlayer();

        /**
        Accelerate the video display
        @param fast     if true the display will be faster
        
        This function accelerates the video display by bypassing all
        widget clipping and overlapping functions. If you enable this
        option the video will always be displayed on top of all other
        widgets.
        */
        void SetFastMode(bool fast);

        static void cb(SDL_Surface* dst, int x, int y, unsigned int w, unsigned 
int h);

        /**
        The MPEG player data
        */
        SMPEG* f;
        SMPEG_Info info;

        /**
        Play the video
        */
        void Play(void);

        /**
        Stop the video
        */
        void Stop(void);

        /**
        Rewind the video back to it's beginning
        */
        void Rewind(void);

        /**
        Pause/Resume playback of the video
        */
        void Pause(void);

        /**
        Seek 'bytes' bytes in the MPEG stream
        @param bytes    distance (in bytes) where to reposition stream
        */
        void Seek(int bytes);

        /**
        Skip 'seconds' seconds in the MPEG stream
        @param seconds  time (in seconds) where to reposition stream
        */
        void Skip(float seconds);
  
        /**
        returns total size of video (in bytes)
        */
        Uint32 totalsize() { return info.total_size; };

        /**
        returns total time of video (in seconds)
        */
        double totaltime() { return info.total_time; };

        /**
        current video status

        return the current status (SMPEG_ERROR | SMPEG_STOPPED | SMPEG_PLAYING)
        of the video
        */
        SMPEGstatus cstat() { return SMPEG_status(f); };

        /**
        returns the current offset (in bytes) of the videostream position
        */
        Uint32 currentoffset() { return info.current_offset; };

        /**
        returns the current time (in seconds) of the videostream position
        */
        double currenttime() { return info.current_time; };

        /**
        catch this event as it can break the mpeg player
        */
        bool SizeWidget(Uint16 w, Uint16 h);
        void eventSizeWidget(Uint16 w, Uint16 h);

protected:
        /**
        Video frame update function

        an update that happens every frame.
        this one just updates the 'info' record.
        */
        virtual void frameupdate();

private:
        static std::map<SDL_Surface*, PG_MPEGPlayer *> hash;
        bool bFastMode;
        SDL_Surface *currentscreen;
};

class PG_MPEGPlayerWindow : public PG_MPEGPlayer {
protected:
        PG_Slider* pos;
public:
        PG_MPEGPlayerWindow(const char *file, PG_Widget *parent, const PG_Rect 
& r)
          : PG_MPEGPlayer(file, parent, r) {
          pos=NULL;
        };
  
        ~PG_MPEGPlayerWindow() { };

        /* this slider will be updated with current player position */
        void handle_position(PG_Slider* slider);

        /* access sigc++ 'slots' *g* */
        bool handle_start(PG_Button* button);
        bool handle_stop(PG_Button* button);
        bool handle_rewind(PG_Button* button);
        bool handle_pause(PG_Button* button);
        bool handle_transparency(PG_Slider* slider, long data);
        bool handle_fastmode(PG_RadioButton* button);
        bool handle_reposition(PG_Slider* slider, long data);

protected:
        void frameupdate();
};

class PG_MoveableMPEGPLayerWindow : public PG_MPEGPlayerWindow {
        bool bDragMode;
public:
        PG_MoveableMPEGPLayerWindow(const char *file, PG_Widget *parent, const 
PG_Rect & r)
          : PG_MPEGPlayerWindow(file, parent, r) {
          bDragMode = false;
        };

        ~PG_MoveableMPEGPLayerWindow() { };

protected:
        bool eventMouseButtonDown(const SDL_MouseButtonEvent *button) {
          bDragMode = true;
          StartWidgetDrag();
          SetCapture();
          return true;
        }
  
        bool eventMouseButtonUp(const SDL_MouseButtonEvent *button) {
          if(bDragMode)
            {
              EndWidgetDrag(button->x, button->y);
              ReleaseCapture();
            }
          bDragMode = false;
          return true;
        }
  
        bool eventMouseMotion (const SDL_MouseMotionEvent *motion) {
          if(!bDragMode) { return true; }
          WidgetDrag(motion->x, motion->y);
          return true;
        }
};

#endif





reply via email to

[Prev in Thread] Current Thread [Next in Thread]