Re: gstreamermm: source file error: '/usr/include/gdkmm-2.4/gdkmm/types.h'



Hi Murray,

Thank you for your advice. I just found out the problem several hours ago... Yes it was a #include problem in my source code and I dont understand why this happened. I think it has something to do with either pkg-config search path or gtkmm & gstreamermm.

According to the error message given by the compiler: "from /home/phongcao/dingo/dingo-backend.h:25" has problem. So I went there and look and it was actually the #include <gtkmm.h> line in my header file:

#ifndef INCLUDED_GSTREAMERMM_H
#define INCLUDED_GSTREAMERMM_H
#include <gstreamermm/element.h>
#include <gstreamermm/pipeline.h>
#include <gstreamermm/bus.h>
#include <gstreamermm/playbin2.h>
#include <gstreamermm/ximagesink.h>
#include <gdk/gdkx.h>
#include <gstreamermm/bus.h>
#include <gstreamermm/caps.h>
#include <gstreamermm/clock.h>
#include <gstreamermm/buffer.h>
#include <gstreamermm/event.h>
#include <gstreamermm/message.h>
#include <gstreamermm/query.h>
#include <gstreamermm/interface.h>
#include <gstreamermm/xoverlay.h>
#endif //INCLUDED_GSTREAMERMM_H

#ifndef INCLUDED_GTKMM_H
#define INCLUDED_GTKMM_H
#include <gtkmm.h>                    
#endif //INCLUDED_GTKMM_H

#ifndef INCLUDED_IOSTREAM
#define INCLUDED_IOSTREAM
#include <iostream>
#endif //INCLUDED_IOSTREAM

I compiled the source code with this command:
g++ -Wall -g -c /home/phongcao/dingo/dingo-backend.cc `pkg-config --cflags --libs gstreamermm-0.10 gtkmm-2.4`

So I just moved the "#include <gtkmm.h>" line on top of INCLUDED_GSTREAMERMM_H and the file was compiled... Not sure what went wrong though but I think something is defining Status as an int inside <gtkmm.h>, and there may also be a variable called Status in <gdk/gdkx.h>. When I dont #include <gdk/gdkx.h> I do not receive the error, but my source code won't compile because it uses the GDK_WINDOW_XID() function. All the classes and global variables in my codes are nested inside a namespace called "Dingo::" so it can not collapse with the enum Status in types.h.

Attached with this email is the source code of my program (before correction). You can download and take a look at it and see what was the problem...

On Mon, Oct 17, 2011 at 6:12 AM, Murray Cumming <murrayc murrayc com> wrote:
On Sat, 2011-10-15 at 16:29 -0400, Phong Cao wrote:
>
> I am trying to create a small music player program in
> GStreamermm-0.10. I did according to the example provided in
> gtkmm-0.10-10 source code. However, when I tried to compiled, the
> program gave the following error:
>
> g++ -Wall -g -c /home/phongcao/dingo/dingo-backend.cc `pkg-config
> --cflags --libs gtkmm-2.4 taglib gstreamermm-0.10 gtk+-2.0`
> In file included from /usr/include/gdkmm-2.4/gdkmm/region.h:66:0,
>                  from /usr/include/gdkmm-2.4/gdkmm/screen.h:32,
>                  from /usr/include/gdkmm-2.4/gdkmm.h:27,
>                  from /usr/include/gtkmm-2.4/gtkmm.h:89,
>                  from /home/phongcao/dingo/dingo-backend.h:25,
>                  from /home/phongcao/dingo/dingo-backend.cc:1:
> /usr/include/gdkmm-2.4/gdkmm/types.h:189:6: error: expected identifier
> before ‘int’

That line is probably this:
enum Status

So it looks like something is #defining Status as int. This is probably
in your own code or something that you #include.

Can you actually build the gstreamermm examples?

If the problem is in something that you #include, you should a) File a
bug about it, and b) #include that file as late as possible, as a little
as possible.

--
murrayc murrayc com
www.murrayc.com
www.openismus.com




--
Phong V. Cao
phngcv gmail com


#include "dingo-backend.h"

Dingo::BackEnd::BackEnd(const std::string &uri, Gtk::DrawingArea* videoarea) {
  d_videoarea = videoarea;
  d_uri = uri;
  
  //connect videoarea to the function called when videoarea is realized 
  (*d_videoarea).signal_realize().connect(sigc::mem_fun(*this, &Dingo::BackEnd::realizeVideoArea));
  
  //create the playbin
  d_playbin = Gst::PlayBin2::create("playbin");
  
  if (!d_playbin) {
    std::cerr << "The playbin could not be created." << std::endl;
  }
  
  //create the videosink
  d_videosink = Gst::XImageSink::create("ximagesink");
  
  if (d_videosink) {
    std::cerr << "The ximagesink could not be created." << std::endl;
  }
  
  //set the videosink property of the playbin to display video
  d_playbin->property_video_sink() = d_videosink;
  
  //set the uri property of the playbin
  d_playbin->property_uri() = d_uri;
  
  //get the bus from pipeline
  Glib::RefPtr<Gst::Bus> bus = d_playbin->get_bus();
  
  //enable synchronous message emission to set up video
  bus->enable_sync_message_emission();
  
  //connect to bus's synchronous message signal so that d_videoarea can be set up for drawing at the appropriate time
  bus->signal_sync_message().connect(sigc::mem_fun(*this, &BackEnd::receiveBusMessageSync));
  
  //add a bus watch to receive messages from pipeline's bus
  d_watch_id = bus->add_watch(sigc::mem_fun(*this, &BackEnd::receiveBusMessage));
}

Dingo::BackEnd::~BackEnd() {

}

void Dingo::BackEnd::realizeVideoArea() {
  //when the videoarea is realized, get its x_window_id
  d_x_window_id = GDK_WINDOW_XID((*d_videoarea).get_window()->gobj());
}

bool Dingo::BackEnd::receiveBusMessage(const Glib::RefPtr<Gst::Bus>& bus, const Glib::RefPtr<Gst::Message>& message) {
  switch (message->get_message_type()) 
  {
    case Gst::MESSAGE_EOS: 
    {
      stop();
      break;
    }
    
    case Gst::MESSAGE_ERROR:
    {
      Glib::RefPtr<Gst::MessageError> msgError = Glib::RefPtr<Gst::MessageError>::cast_dynamic(message);
      
      if (msgError) {
        Glib::Error err;
        err = msgError->parse();
        std::cerr << "Error: " << err.what() << std::endl;
      }
      else 
        std::cerr << "Error." << std::endl;
        
      stop();
      break;
    }
    
    default: 
    {
    }
  }
  return true;
}

void Dingo::BackEnd::receiveBusMessageSync(const Glib::RefPtr<Gst::Message>& message) {
  //ignore anything but 'prepare-xwindow-id' element messages
  if (message->get_message_type() != Gst::MESSAGE_ELEMENT)
    return;
    
  if (!message->get_structure().has_name("prepare-xwindow-id")) 
    return; 
    
  Glib::RefPtr<Gst::Element> element = Glib::RefPtr<Gst::Element>::cast_dynamic(message->get_source());
  
  Glib::RefPtr< Gst::ElementInterfaced<Gst::XOverlay> > xoverlay = Gst::Interface::cast <Gst::XOverlay>(element);
  
  if (xoverlay) {
    xoverlay->set_xwindow_id(d_x_window_id);
  }
}

void Dingo::BackEnd::play() {
  d_playbin->set_state(Gst::STATE_PLAYING);
}

void Dingo::BackEnd::stop() {
  d_playbin->set_state(Gst::STATE_NULL);
}

void Dingo::BackEnd::pause() {
  d_playbin->set_state(Gst::STATE_PAUSED);
}

void Dingo::BackEnd::resume() {
  d_playbin->set_state(Gst::STATE_PLAYING);
}

void Dingo::BackEnd::reset() {
  d_playbin->seek(1.0, Gst::FORMAT_TIME, Gst::SEEK_FLAG_FLUSH | Gst::SEEK_FLAG_KEY_UNIT, Gst::SEEK_TYPE_SET, 0, Gst::SEEK_TYPE_NONE, Gst::CLOCK_TIME_NONE);
}

void Dingo::BackEnd::seek(gint64 value) {
  d_playbin->seek(1.0, Gst::FORMAT_TIME, Gst::SEEK_FLAG_FLUSH | Gst::SEEK_FLAG_KEY_UNIT, Gst::SEEK_TYPE_CUR, value, Gst::SEEK_TYPE_NONE, Gst::CLOCK_TIME_NONE);
}

void Dingo::BackEnd::seekAbsolute(gint64 value) {
  d_playbin->seek(1.0, Gst::FORMAT_TIME, Gst::SEEK_FLAG_FLUSH | Gst::SEEK_FLAG_KEY_UNIT, Gst::SEEK_TYPE_SET, value, Gst::SEEK_TYPE_NONE, Gst::CLOCK_TIME_NONE);
}

gint64 Dingo::BackEnd::queryPosition() {
  gint64 pos;
  Gst::Format fmt = Gst::FORMAT_TIME;

  d_playbin->query_position(fmt, pos);
  
  return pos;
}

gint64 Dingo::BackEnd::queryDuration() {
  gint64 dur;
  Gst::Format fmt = Gst::FORMAT_TIME;

  d_playbin->query_duration(fmt, dur);
  
  return dur;
}
#ifndef INCLUDED_DINGO_BACKEND_H
#define INCLUDED_DINGO_BACKEND_H

#ifndef INCLUDED_GSTREAMERMM_H
#define INCLUDED_GSTREAMERMM_H
#include <gstreamermm/element.h>
#include <gstreamermm/pipeline.h>
#include <gstreamermm/bus.h>
#include <gstreamermm/playbin2.h>
#include <gstreamermm/ximagesink.h>
#include <gdk/gdkx.h>
#include <gstreamermm/bus.h>
#include <gstreamermm/caps.h>
#include <gstreamermm/clock.h>
#include <gstreamermm/buffer.h>
#include <gstreamermm/event.h>
#include <gstreamermm/message.h>
#include <gstreamermm/query.h>
#include <gstreamermm/interface.h>
#include <gstreamermm/xoverlay.h>
#endif //INCLUDED_GSTREAMERMM_H

#ifndef INCLUDED_GTKMM_H
#define INCLUDED_GTKMM_H
#include <gtkmm.h>
#endif //INCLUDED_GTKMM_H

#ifndef INCLUDED_IOSTREAM
#define INCLUDED_IOSTREAM
#include <iostream>
#endif //INCLUDED_IOSTREAM

namespace Dingo {
  class BackEnd {
    public:
      //CREATORS
      BackEnd(const std::string &uri, Gtk::DrawingArea* videoarea);
      virtual ~BackEnd();
      
      //MANIPULATORS
      void play();
      void stop();
      void pause();
      void resume();
      void reset();
      void seek(gint64 value);
      void seekAbsolute(gint64 value);
      gint64 queryPosition();
      gint64 queryDuration();
    
    private:
      //DATA MEMBERS
      Glib::RefPtr<Gst::PlayBin2> d_playbin;
      Glib::RefPtr<Gst::XImageSink> d_videosink;
      Gtk::DrawingArea* d_videoarea;
      std::string d_uri;
      int d_watch_id;
      gulong d_x_window_id;
    
      //BUS & MESSAGES
      void realizeVideoArea();
      bool receiveBusMessage(const Glib::RefPtr<Gst::Bus>& bus, const Glib::RefPtr<Gst::Message>& message);
      void receiveBusMessageSync(const Glib::RefPtr<Gst::Message>& message);
  };
}

#endif //INCLUDED_DINGO_BACKEND_H


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