src/3rdparty/phonon/gstreamer/phononsrc.cpp
changeset 3 41300fa6a67c
parent 0 1918ee327afb
equal deleted inserted replaced
2:56cd8111b7f7 3:41300fa6a67c
   107 }
   107 }
   108 
   108 
   109 static void phonon_src_init (PhononSrc * src, PhononSrcClass * g_class)
   109 static void phonon_src_init (PhononSrc * src, PhononSrcClass * g_class)
   110 {
   110 {
   111     Q_UNUSED(g_class);
   111     Q_UNUSED(g_class);
       
   112 #ifndef QT_NO_PHONON_ABSTRACTMEDIASTREAM
   112     src->device = 0;
   113     src->device = 0;
       
   114 #else
       
   115     Q_UNUSED(src);
       
   116 #endif
   113 }
   117 }
   114 
   118 
   115 static void phonon_src_finalize (GObject * object)
   119 static void phonon_src_finalize (GObject * object)
   116 {
   120 {
       
   121 #ifndef QT_NO_PHONON_ABSTRACTMEDIASTREAM
   117     PhononSrc *src;
   122     PhononSrc *src;
   118     src = GST_PHONON_SRC (object);
   123     src = GST_PHONON_SRC (object);
   119     delete src->device;
   124     delete src->device;
   120     src->device = 0;
   125     src->device = 0;
       
   126 #endif //QT_NO_PHONON_ABSTRACTMEDIASTREAM
   121     G_OBJECT_CLASS (parent_class)->finalize (object);
   127     G_OBJECT_CLASS (parent_class)->finalize (object);
   122 }
   128 }
   123 
   129 
       
   130 #ifndef QT_NO_PHONON_ABSTRACTMEDIASTREAM
   124 static gboolean phonon_src_set_device(PhononSrc * src, StreamReader* device)
   131 static gboolean phonon_src_set_device(PhononSrc * src, StreamReader* device)
   125 {
   132 {
   126     GstState state;
   133     GstState state;
   127     // The element must be stopped in order to do this
   134     // The element must be stopped in order to do this
   128     GST_OBJECT_LOCK (src);
   135     GST_OBJECT_LOCK (src);
   143         //GST_DEBUG_OBJECT (src, "setting location in wrong state");
   150         //GST_DEBUG_OBJECT (src, "setting location in wrong state");
   144         GST_OBJECT_UNLOCK (src);
   151         GST_OBJECT_UNLOCK (src);
   145         return FALSE;
   152         return FALSE;
   146     }
   153     }
   147 }
   154 }
       
   155 #endif //QT_NO_PHONON_ABSTRACTMEDIASTREAM
   148 
   156 
   149 static void phonon_src_set_property (GObject * object, guint prop_id, const GValue * value, GParamSpec * pspec)
   157 static void phonon_src_set_property (GObject * object, guint prop_id, const GValue * value, GParamSpec * pspec)
   150 {
   158 {
   151     PhononSrc *src;
   159     PhononSrc *src;
   152     g_return_if_fail (GST_IS_PHONON_SRC (object));
   160     g_return_if_fail (GST_IS_PHONON_SRC (object));
   153     src = GST_PHONON_SRC (object);
   161     src = GST_PHONON_SRC (object);
   154 
   162 
   155     switch (prop_id) {
   163     switch (prop_id) {
       
   164 #ifndef QT_NO_PHONON_ABSTRACTMEDIASTREAM
   156     case ARG_PHONONSRC:
   165     case ARG_PHONONSRC:
   157     {
   166     {
   158         StreamReader *dev = (StreamReader*)(g_value_get_pointer(value));
   167         StreamReader *dev = (StreamReader*)(g_value_get_pointer(value));
   159         if (dev)
   168         if (dev)
   160             phonon_src_set_device(src, dev);
   169             phonon_src_set_device(src, dev);
   161         break;
   170         break;
   162     }
   171     }
       
   172 #else
       
   173     Q_UNUSED(value);
       
   174 #endif //QT_NO_PHONON_ABSTRACTMEDIASTREAM
   163    default:
   175    default:
   164        G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
   176        G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
   165        break;
   177        break;
   166    }
   178    }
   167 }
   179 }
   172     PhononSrc *src;
   184     PhononSrc *src;
   173     g_return_if_fail (GST_IS_PHONON_SRC (object));
   185     g_return_if_fail (GST_IS_PHONON_SRC (object));
   174     src = GST_PHONON_SRC (object);
   186     src = GST_PHONON_SRC (object);
   175 
   187 
   176     switch (prop_id) {
   188     switch (prop_id) {
       
   189 #ifndef QT_NO_PHONON_ABSTRACTMEDIASTREAM
   177     case ARG_PHONONSRC:
   190     case ARG_PHONONSRC:
   178         g_value_set_pointer(value, src->device);
   191         g_value_set_pointer(value, src->device);
   179         break;
   192         break;
       
   193 #else //QT_NO_PHONON_ABSTRACTMEDIASTREAM
       
   194     Q_UNUSED(value);
       
   195 #endif //QT_NO_PHONON_ABSTRACTMEDIASTREAM
   180     default:
   196     default:
   181         G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
   197         G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
   182         break;
   198         break;
   183     }
   199     }
   184 }
   200 }
   185 
   201 
   186 static GstFlowReturn phonon_src_create_read (PhononSrc * src, guint64 offset, guint length, GstBuffer ** buffer)
   202 static GstFlowReturn phonon_src_create_read (PhononSrc * src, guint64 offset, guint length, GstBuffer ** buffer)
   187 {
   203 {
       
   204 #ifndef QT_NO_PHONON_ABSTRACTMEDIASTREAM
   188     Q_ASSERT(src->device);
   205     Q_ASSERT(src->device);
   189     if (!src->device)
   206     if (!src->device)
   190         return GST_FLOW_ERROR;
   207         return GST_FLOW_ERROR;
   191 
   208 
   192     GstBuffer *buf = gst_buffer_new_and_alloc (length);
   209     GstBuffer *buf = gst_buffer_new_and_alloc (length);
   202         return GST_FLOW_OK;
   219         return GST_FLOW_OK;
   203     }
   220     }
   204 
   221 
   205     gst_mini_object_unref(GST_MINI_OBJECT(buf));
   222     gst_mini_object_unref(GST_MINI_OBJECT(buf));
   206     return GST_FLOW_ERROR;
   223     return GST_FLOW_ERROR;
       
   224 #else //QT_NO_PHONON_ABSTRACTMEDIASTREAM
       
   225     Q_UNUSED(src);
       
   226     Q_UNUSED(offset);
       
   227     Q_UNUSED(length);
       
   228     Q_UNUSED(buffer);
       
   229     return GST_FLOW_ERROR;
       
   230 #endif //QT_NO_PHONON_ABSTRACTMEDIASTREAM
   207 }
   231 }
   208 
   232 
   209 static GstFlowReturn phonon_src_create (GstBaseSrc * basesrc, guint64 offset, guint length, GstBuffer ** buffer)
   233 static GstFlowReturn phonon_src_create (GstBaseSrc * basesrc, guint64 offset, guint length, GstBuffer ** buffer)
   210 {
   234 {
   211     PhononSrc *src;
   235     PhononSrc *src;
   216 }
   240 }
   217 
   241 
   218 static gboolean phonon_src_is_seekable (GstBaseSrc * basesrc)
   242 static gboolean phonon_src_is_seekable (GstBaseSrc * basesrc)
   219 {
   243 {
   220     PhononSrc *src = GST_PHONON_SRC (basesrc);
   244     PhononSrc *src = GST_PHONON_SRC (basesrc);
       
   245 #ifndef QT_NO_PHONON_ABSTRACTMEDIASTREAM
   221     if (src->device)
   246     if (src->device)
   222         return src->device->streamSeekable();
   247         return src->device->streamSeekable();
       
   248 #endif //QT_NO_PHONON_ABSTRACTMEDIASTREAM
   223     return false;
   249     return false;
   224 }
   250 }
   225 
   251 
   226 static gboolean phonon_src_get_size (GstBaseSrc * basesrc, guint64 * size)
   252 static gboolean phonon_src_get_size (GstBaseSrc * basesrc, guint64 * size)
   227 {
   253 {
       
   254 #ifndef QT_NO_PHONON_ABSTRACTMEDIASTREAM
   228     PhononSrc *src;
   255     PhononSrc *src;
   229     src = GST_PHONON_SRC (basesrc);
   256     src = GST_PHONON_SRC (basesrc);
   230     if (src->device && src->device->streamSeekable()) {
   257     if (src->device && src->device->streamSeekable()) {
   231         *size = src->device->streamSize();
   258         *size = src->device->streamSize();
   232         return TRUE;
   259         return TRUE;
   233     }
   260     }
       
   261 #endif //QT_NO_PHONON_ABSTRACTMEDIASTREAM
   234     *size = 0;
   262     *size = 0;
   235     return FALSE;
   263     return FALSE;
   236 }
   264 }
   237 
   265 
   238 // Necessary to go to READY state
   266 // Necessary to go to READY state