1 /* 2 * This file is part of gtkD. 3 * 4 * gtkD is free software; you can redistribute it and/or modify 5 * it under the terms of the GNU Lesser General Public License 6 * as published by the Free Software Foundation; either version 3 7 * of the License, or (at your option) any later version, with 8 * some exceptions, please read the COPYING file. 9 * 10 * gtkD is distributed in the hope that it will be useful, 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 * GNU Lesser General Public License for more details. 14 * 15 * You should have received a copy of the GNU Lesser General Public License 16 * along with gtkD; if not, write to the Free Software 17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA 18 */ 19 20 // generated automatically - do not change 21 // find conversion definition on APILookup.txt 22 // implement new conversion functionalities on the wrap.utils pakage 23 24 25 module gtk.MediaStream; 26 27 private import gdk.PaintableIF; 28 private import gdk.PaintableT; 29 private import gdk.Surface; 30 private import glib.ErrorG; 31 private import glib.Str; 32 private import gobject.ObjectG; 33 private import gtk.c.functions; 34 public import gtk.c.types; 35 36 37 /** 38 * `GtkMediaStream` is the integration point for media playback inside GTK. 39 * 40 * GTK provides an implementation of the `GtkMediaStream` interface that 41 * is called [class@Gtk.MediaFile]. 42 * 43 * Apart from application-facing API for stream playback, `GtkMediaStream` 44 * has a number of APIs that are only useful for implementations and should 45 * not be used in applications: 46 * [method@Gtk.MediaStream.prepared], 47 * [method@Gtk.MediaStream.unprepared], 48 * [method@Gtk.MediaStream.update], 49 * [method@Gtk.MediaStream.ended], 50 * [method@Gtk.MediaStream.seek_success], 51 * [method@Gtk.MediaStream.seek_failed], 52 * [method@Gtk.MediaStream.gerror], 53 * [method@Gtk.MediaStream.error], 54 * [method@Gtk.MediaStream.error_valist]. 55 */ 56 public class MediaStream : ObjectG, PaintableIF 57 { 58 /** the main Gtk struct */ 59 protected GtkMediaStream* gtkMediaStream; 60 61 /** Get the main Gtk struct */ 62 public GtkMediaStream* getMediaStreamStruct(bool transferOwnership = false) 63 { 64 if (transferOwnership) 65 ownedRef = false; 66 return gtkMediaStream; 67 } 68 69 /** the main Gtk struct as a void* */ 70 protected override void* getStruct() 71 { 72 return cast(void*)gtkMediaStream; 73 } 74 75 /** 76 * Sets our main struct and passes it to the parent class. 77 */ 78 public this (GtkMediaStream* gtkMediaStream, bool ownedRef = false) 79 { 80 this.gtkMediaStream = gtkMediaStream; 81 super(cast(GObject*)gtkMediaStream, ownedRef); 82 } 83 84 // add the Paintable capabilities 85 mixin PaintableT!(GtkMediaStream); 86 87 88 /** */ 89 public static GType getType() 90 { 91 return gtk_media_stream_get_type(); 92 } 93 94 /** 95 * Pauses the media stream and marks it as ended. 96 * 97 * This is a hint only, calls to GtkMediaStream.play() 98 * may still happen. 99 * 100 * The media stream must be prepared when this function is called. 101 */ 102 public void ended() 103 { 104 gtk_media_stream_ended(gtkMediaStream); 105 } 106 107 /** 108 * Sets @self into an error state using a printf()-style format string. 109 * 110 * This is a utility function that calls [method@Gtk.MediaStream.gerror]. 111 * See that function for details. 112 * 113 * Params: 114 * domain = error domain 115 * code = error code 116 * format = printf()-style format for error message 117 * args = `va_list` of parameters for the message format 118 */ 119 public void errorValist(GQuark domain, int code, string format, void* args) 120 { 121 gtk_media_stream_error_valist(gtkMediaStream, domain, code, Str.toStringz(format), args); 122 } 123 124 /** 125 * Sets @self into an error state. 126 * 127 * This will pause the stream (you can check for an error 128 * via [method@Gtk.MediaStream.get_error] in your 129 * GtkMediaStream.pause() implementation), abort pending 130 * seeks and mark the stream as prepared. 131 * 132 * if the stream is already in an error state, this call 133 * will be ignored and the existing error will be retained. 134 * 135 * To unset an error, the stream must be reset via a call to 136 * [method@Gtk.MediaStream.unprepared]. 137 * 138 * Params: 139 * error = the `GError` to set 140 */ 141 public void gerror(ErrorG error) 142 { 143 gtk_media_stream_gerror(gtkMediaStream, (error is null) ? null : error.getErrorGStruct(true)); 144 } 145 146 /** 147 * Gets the duration of the stream. 148 * 149 * If the duration is not known, 0 will be returned. 150 * 151 * Returns: the duration of the stream or 0 if not known. 152 */ 153 public long getDuration() 154 { 155 return gtk_media_stream_get_duration(gtkMediaStream); 156 } 157 158 /** 159 * Returns whether the streams playback is finished. 160 * 161 * Returns: %TRUE if playback is finished 162 */ 163 public bool getEnded() 164 { 165 return gtk_media_stream_get_ended(gtkMediaStream) != 0; 166 } 167 168 /** 169 * If the stream is in an error state, returns the `GError` 170 * explaining that state. 171 * 172 * Any type of error can be reported here depending on the 173 * implementation of the media stream. 174 * 175 * A media stream in an error cannot be operated on, calls 176 * like [method@Gtk.MediaStream.play] or 177 * [method@Gtk.MediaStream.seek] will not have any effect. 178 * 179 * `GtkMediaStream` itself does not provide a way to unset 180 * an error, but implementations may provide options. For example, 181 * a [class@Gtk.MediaFile] will unset errors when a new source is 182 * set, e.g. with [method@Gtk.MediaFile.set_file]. 183 * 184 * Returns: %NULL if not in an 185 * error state or the `GError` of the stream 186 */ 187 public ErrorG getError() 188 { 189 auto __p = gtk_media_stream_get_error(gtkMediaStream); 190 191 if(__p is null) 192 { 193 return null; 194 } 195 196 return new ErrorG(cast(GError*) __p); 197 } 198 199 /** 200 * Returns whether the stream is set to loop. 201 * 202 * See [method@Gtk.MediaStream.set_loop] for details. 203 * 204 * Returns: %TRUE if the stream should loop 205 */ 206 public bool getLoop() 207 { 208 return gtk_media_stream_get_loop(gtkMediaStream) != 0; 209 } 210 211 /** 212 * Returns whether the audio for the stream is muted. 213 * 214 * See [method@Gtk.MediaStream.set_muted] for details. 215 * 216 * Returns: %TRUE if the stream is muted 217 */ 218 public bool getMuted() 219 { 220 return gtk_media_stream_get_muted(gtkMediaStream) != 0; 221 } 222 223 /** 224 * Return whether the stream is currently playing. 225 * 226 * Returns: %TRUE if the stream is playing 227 */ 228 public bool getPlaying() 229 { 230 return gtk_media_stream_get_playing(gtkMediaStream) != 0; 231 } 232 233 /** 234 * Returns the current presentation timestamp in microseconds. 235 * 236 * Returns: the timestamp in microseconds 237 */ 238 public long getTimestamp() 239 { 240 return gtk_media_stream_get_timestamp(gtkMediaStream); 241 } 242 243 /** 244 * Returns the volume of the audio for the stream. 245 * 246 * See [method@Gtk.MediaStream.set_volume] for details. 247 * 248 * Returns: volume of the stream from 0.0 to 1.0 249 */ 250 public double getVolume() 251 { 252 return gtk_media_stream_get_volume(gtkMediaStream); 253 } 254 255 /** 256 * Returns whether the stream has audio. 257 * 258 * Returns: %TRUE if the stream has audio 259 */ 260 public bool hasAudio() 261 { 262 return gtk_media_stream_has_audio(gtkMediaStream) != 0; 263 } 264 265 /** 266 * Returns whether the stream has video. 267 * 268 * Returns: %TRUE if the stream has video 269 */ 270 public bool hasVideo() 271 { 272 return gtk_media_stream_has_video(gtkMediaStream) != 0; 273 } 274 275 /** 276 * Returns whether the stream has finished initializing. 277 * 278 * At this point the existence of audio and video is known. 279 * 280 * Returns: %TRUE if the stream is prepared 281 */ 282 public bool isPrepared() 283 { 284 return gtk_media_stream_is_prepared(gtkMediaStream) != 0; 285 } 286 287 /** 288 * Checks if a stream may be seekable. 289 * 290 * This is meant to be a hint. Streams may not allow seeking even if 291 * this function returns %TRUE. However, if this function returns 292 * %FALSE, streams are guaranteed to not be seekable and user interfaces 293 * may hide controls that allow seeking. 294 * 295 * It is allowed to call [method@Gtk.MediaStream.seek] on a non-seekable 296 * stream, though it will not do anything. 297 * 298 * Returns: %TRUE if the stream may support seeking 299 */ 300 public bool isSeekable() 301 { 302 return gtk_media_stream_is_seekable(gtkMediaStream) != 0; 303 } 304 305 /** 306 * Checks if there is currently a seek operation going on. 307 * 308 * Returns: %TRUE if a seek operation is ongoing. 309 */ 310 public bool isSeeking() 311 { 312 return gtk_media_stream_is_seeking(gtkMediaStream) != 0; 313 } 314 315 /** 316 * Pauses playback of the stream. 317 * 318 * If the stream is not playing, do nothing. 319 */ 320 public void pause() 321 { 322 gtk_media_stream_pause(gtkMediaStream); 323 } 324 325 /** 326 * Starts playing the stream. 327 * 328 * If the stream is in error or already playing, do nothing. 329 */ 330 public void play() 331 { 332 gtk_media_stream_play(gtkMediaStream); 333 } 334 335 /** 336 * Called by `GtkMediaStream` implementations to advertise the stream 337 * being ready to play and providing details about the stream. 338 * 339 * Note that the arguments are hints. If the stream implementation 340 * cannot determine the correct values, it is better to err on the 341 * side of caution and return %TRUE. User interfaces will use those 342 * values to determine what controls to show. 343 * 344 * This function may not be called again until the stream has been 345 * reset via [method@Gtk.MediaStream.unprepared]. 346 * 347 * Params: 348 * hasAudio = %TRUE if the stream should advertise audio support 349 * hasVideo = %TRUE if the stream should advertise video support 350 * seekable = %TRUE if the stream should advertise seekability 351 * duration = The duration of the stream or 0 if unknown 352 */ 353 public void prepared(bool hasAudio, bool hasVideo, bool seekable, long duration) 354 { 355 gtk_media_stream_prepared(gtkMediaStream, hasAudio, hasVideo, seekable, duration); 356 } 357 358 /** 359 * Called by users to attach the media stream to a `GdkSurface` they manage. 360 * 361 * The stream can then access the resources of @surface for its 362 * rendering purposes. In particular, media streams might want to 363 * create a `GdkGLContext` or sync to the `GdkFrameClock`. 364 * 365 * Whoever calls this function is responsible for calling 366 * [method@Gtk.MediaStream.unrealize] before either the stream 367 * or @surface get destroyed. 368 * 369 * Multiple calls to this function may happen from different 370 * users of the video, even with the same @surface. Each of these 371 * calls must be followed by its own call to 372 * [method@Gtk.MediaStream.unrealize]. 373 * 374 * It is not required to call this function to make a media stream work. 375 * 376 * Params: 377 * surface = a `GdkSurface` 378 */ 379 public void realize(Surface surface) 380 { 381 gtk_media_stream_realize(gtkMediaStream, (surface is null) ? null : surface.getSurfaceStruct()); 382 } 383 384 /** 385 * Start a seek operation on @self to @timestamp. 386 * 387 * If @timestamp is out of range, it will be clamped. 388 * 389 * Seek operations may not finish instantly. While a 390 * seek operation is in process, the [property@Gtk.MediaStream:seeking] 391 * property will be set. 392 * 393 * When calling gtk_media_stream_seek() during an 394 * ongoing seek operation, the new seek will override 395 * any pending seek. 396 * 397 * Params: 398 * timestamp = timestamp to seek to. 399 */ 400 public void seek(long timestamp) 401 { 402 gtk_media_stream_seek(gtkMediaStream, timestamp); 403 } 404 405 /** 406 * Ends a seek operation started via GtkMediaStream.seek() as a failure. 407 * 408 * This will not cause an error on the stream and will assume that 409 * playback continues as if no seek had happened. 410 * 411 * See [method@Gtk.MediaStream.seek_success] for the other way of 412 * ending a seek. 413 */ 414 public void seekFailed() 415 { 416 gtk_media_stream_seek_failed(gtkMediaStream); 417 } 418 419 /** 420 * Ends a seek operation started via GtkMediaStream.seek() successfully. 421 * 422 * This function will unset the GtkMediaStream:ended property 423 * if it was set. 424 * 425 * See [method@Gtk.MediaStream.seek_failed] for the other way of 426 * ending a seek. 427 */ 428 public void seekSuccess() 429 { 430 gtk_media_stream_seek_success(gtkMediaStream); 431 } 432 433 /** 434 * Sets whether the stream should loop. 435 * 436 * In this case, it will attempt to restart playback 437 * from the beginning instead of stopping at the end. 438 * 439 * Not all streams may support looping, in particular 440 * non-seekable streams. Those streams will ignore the 441 * loop setting and just end. 442 * 443 * Params: 444 * loop = %TRUE if the stream should loop 445 */ 446 public void setLoop(bool loop) 447 { 448 gtk_media_stream_set_loop(gtkMediaStream, loop); 449 } 450 451 /** 452 * Sets whether the audio stream should be muted. 453 * 454 * Muting a stream will cause no audio to be played, but it 455 * does not modify the volume. This means that muting and 456 * then unmuting the stream will restore the volume settings. 457 * 458 * If the stream has no audio, calling this function will 459 * still work but it will not have an audible effect. 460 * 461 * Params: 462 * muted = %TRUE if the stream should be muted 463 */ 464 public void setMuted(bool muted) 465 { 466 gtk_media_stream_set_muted(gtkMediaStream, muted); 467 } 468 469 /** 470 * Starts or pauses playback of the stream. 471 * 472 * Params: 473 * playing = whether to start or pause playback 474 */ 475 public void setPlaying(bool playing) 476 { 477 gtk_media_stream_set_playing(gtkMediaStream, playing); 478 } 479 480 /** 481 * Sets the volume of the audio stream. 482 * 483 * This function call will work even if the stream is muted. 484 * 485 * The given @volume should range from 0.0 for silence to 1.0 486 * for as loud as possible. Values outside of this range will 487 * be clamped to the nearest value. 488 * 489 * If the stream has no audio or is muted, calling this function 490 * will still work but it will not have an immediate audible effect. 491 * When the stream is unmuted, the new volume setting will take effect. 492 * 493 * Params: 494 * volume = New volume of the stream from 0.0 to 1.0 495 */ 496 public void setVolume(double volume) 497 { 498 gtk_media_stream_set_volume(gtkMediaStream, volume); 499 } 500 501 /** 502 * Resets a given media stream implementation. 503 * 504 * [method@Gtk.MediaStream.prepared] can then be called again. 505 * 506 * This function will also reset any error state the stream was in. 507 */ 508 public void unprepared() 509 { 510 gtk_media_stream_unprepared(gtkMediaStream); 511 } 512 513 /** 514 * Undoes a previous call to gtk_media_stream_realize(). 515 * 516 * This causes the stream to release all resources it had 517 * allocated from @surface. 518 * 519 * Params: 520 * surface = the `GdkSurface` the stream was realized with 521 */ 522 public void unrealize(Surface surface) 523 { 524 gtk_media_stream_unrealize(gtkMediaStream, (surface is null) ? null : surface.getSurfaceStruct()); 525 } 526 527 /** 528 * Media stream implementations should regularly call this 529 * function to update the timestamp reported by the stream. 530 * 531 * It is up to implementations to call this at the frequency 532 * they deem appropriate. 533 * 534 * The media stream must be prepared when this function is called. 535 * 536 * Params: 537 * timestamp = the new timestamp 538 */ 539 public void update(long timestamp) 540 { 541 gtk_media_stream_update(gtkMediaStream, timestamp); 542 } 543 }