libextractor

GNU libextractor
Log | Files | Refs | Submodules | README | LICENSE

mediagst.h (3654B)


      1 /*
      2      This file is part of libextractor.
      3      Copyright (C) 2026 Vidyut Samanta and Christian Grothoff
      4 
      5      libextractor is free software; you can redistribute it and/or modify
      6      it under the terms of the GNU General Public License as published
      7      by the Free Software Foundation; either version 3, or (at your
      8      option) any later version.
      9 
     10      libextractor is distributed in the hope that it will be useful, but
     11      WITHOUT ANY WARRANTY; without even the implied warranty of
     12      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
     13      General Public License for more details.
     14 
     15      You should have received a copy of the GNU General Public License
     16      along with libextractor; see the file COPYING.  If not, write to the
     17      Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
     18      Boston, MA 02110-1301, USA.
     19  */
     20 /**
     21  * @file plugins/mediagst.h
     22  * @brief plumbing between an extraction context and a GStreamer pipeline
     23  * @author Christian Grothoff
     24  *
     25  * Shared by thumbnailgst and previewgst.  Both drive a "playbin" reading
     26  * from an "appsrc://" URI that we feed from the extraction context;
     27  * playbin is used rather than a hand-built decodebin pipeline because it
     28  * already knows how to pick a stream and how not to stall on the streams
     29  * we are not interested in.
     30  */
     31 #ifndef MEDIAGST_H
     32 #define MEDIAGST_H
     33 
     34 #include "extractor.h"
     35 #include "mediautil.h"
     36 
     37 #include <gst/gst.h>
     38 
     39 /**
     40  * Values of playbin's "flags" property.  The enum is not part of any
     41  * installed header, so we spell out the bits we use.
     42  */
     43 #define EXTRACTOR_GST_PLAY_FLAG_VIDEO 0x00000001
     44 
     45 /**
     46  * Play the audio stream.
     47  */
     48 #define EXTRACTOR_GST_PLAY_FLAG_AUDIO 0x00000002
     49 
     50 
     51 /**
     52  * State of a GStreamer pipeline reading from an extraction context.
     53  */
     54 struct EXTRACTOR_GstIO
     55 {
     56   /**
     57    * Extraction context we are reading from.
     58    */
     59   struct EXTRACTOR_ExtractContext *ec;
     60 
     61   /**
     62    * Current read position in the file.
     63    */
     64   uint64_t offset;
     65 
     66   /**
     67    * Size of the file, 0 if unknown.
     68    */
     69   uint64_t length;
     70 };
     71 
     72 
     73 /**
     74  * Create a playbin that reads from @a ec, with the given sinks.  The
     75  * pipeline is returned in state NULL; the caller sets it to PAUSED.
     76  *
     77  * @param[out] io I/O state to initialize
     78  * @param ec extraction context to read from
     79  * @param flags value for playbin's "flags" property
     80  * @param video_sink sink to use for video, consumed
     81  * @param audio_sink sink to use for audio, consumed
     82  * @return the pipeline, or NULL if GStreamer could not provide one
     83  */
     84 GstElement *
     85 EXTRACTOR_gst_playbin_ (struct EXTRACTOR_GstIO *io,
     86                         struct EXTRACTOR_ExtractContext *ec,
     87                         unsigned int flags,
     88                         GstElement *video_sink,
     89                         GstElement *audio_sink);
     90 
     91 
     92 /**
     93  * Wait for @a pipeline to finish its current asynchronous state change.
     94  *
     95  * @param pipeline pipeline to watch
     96  * @param timeout how long to wait, in nanoseconds
     97  * @return 1 if the pipeline is ready, 0 on error, EOS or timeout
     98  */
     99 int
    100 EXTRACTOR_gst_wait_async_ (GstElement *pipeline,
    101                            GstClockTime timeout);
    102 
    103 
    104 /**
    105  * Determine where in the media we should start sampling: @a offset
    106  * seconds in, but never past a third of the duration.
    107  *
    108  * @param pipeline prerolled pipeline
    109  * @param offset desired position in seconds
    110  * @param[out] duration set to the duration in nanoseconds, 0 if unknown
    111  * @return position to sample at, in nanoseconds
    112  */
    113 gint64
    114 EXTRACTOR_gst_sample_position_ (GstElement *pipeline,
    115                                 unsigned int offset,
    116                                 gint64 *duration);
    117 
    118 #endif
    119 
    120 /* end of mediagst.h */