gst_plugins_base/gst-libs/gst/audio/gstringbuffer.h
changeset 0 0e761a78d257
child 8 4a7fac7dd34a
equal deleted inserted replaced
-1:000000000000 0:0e761a78d257
       
     1 /* GStreamer
       
     2  * Copyright (C) 1999,2000 Erik Walthinsen <omega@cse.ogi.edu>
       
     3  *                    2005 Wim Taymans <wim@fluendo.com>
       
     4  *
       
     5  * gstringbuffer.h:
       
     6  *
       
     7  * This library is free software; you can redistribute it and/or
       
     8  * modify it under the terms of the GNU Library General Public
       
     9  * License as published by the Free Software Foundation; either
       
    10  * version 2 of the License, or (at your option) any later version.
       
    11  *
       
    12  * This library is distributed in the hope that it will be useful,
       
    13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
       
    14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
       
    15  * Library General Public License for more details.
       
    16  *
       
    17  * You should have received a copy of the GNU Library General Public
       
    18  * License along with this library; if not, write to the
       
    19  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
       
    20  * Boston, MA 02111-1307, USA.
       
    21  */
       
    22 
       
    23 #ifndef __GST_RING_BUFFER_H__
       
    24 #define __GST_RING_BUFFER_H__
       
    25 
       
    26 #include <gst/gst.h>
       
    27 
       
    28 G_BEGIN_DECLS
       
    29 
       
    30 #define GST_TYPE_RING_BUFFER             (gst_ring_buffer_get_type())
       
    31 #define GST_RING_BUFFER(obj)             (G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_RING_BUFFER,GstRingBuffer))
       
    32 #define GST_RING_BUFFER_CLASS(klass)     (G_TYPE_CHECK_CLASS_CAST((klass),GST_TYPE_RING_BUFFER,GstRingBufferClass))
       
    33 #define GST_RING_BUFFER_GET_CLASS(obj)   (G_TYPE_INSTANCE_GET_CLASS ((obj), GST_TYPE_RING_BUFFER, GstRingBufferClass))
       
    34 #define GST_RING_BUFFER_CAST(obj)        ((GstRingBuffer *)obj)
       
    35 #define GST_IS_RING_BUFFER(obj)          (G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_RING_BUFFER))
       
    36 #define GST_IS_RING_BUFFER_CLASS(klass)  (G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_RING_BUFFER))
       
    37 
       
    38 typedef struct _GstRingBuffer GstRingBuffer;
       
    39 typedef struct _GstRingBufferClass GstRingBufferClass;
       
    40 typedef struct _GstRingBufferSpec GstRingBufferSpec;
       
    41 
       
    42 /**
       
    43  * GstRingBufferCallback:
       
    44  * @rbuf: a #GstRingBuffer
       
    45  * @data: target to fill
       
    46  * @len: amount to fill
       
    47  * @user_data: user data
       
    48  *
       
    49  * This function is set with gst_ring_buffer_set_callback() and is
       
    50  * called to fill the memory at @data with @len bytes of samples. 
       
    51  */
       
    52 typedef void (*GstRingBufferCallback) (GstRingBuffer *rbuf, guint8* data, guint len, gpointer user_data);
       
    53 
       
    54 /**
       
    55  * GstRingBufferState:
       
    56  * @GST_RING_BUFFER_STATE_STOPPED: The ringbuffer is stopped
       
    57  * @GST_RING_BUFFER_STATE_PAUSED: The ringbuffer is paused
       
    58  * @GST_RING_BUFFER_STATE_STARTED: The ringbuffer is started
       
    59  *
       
    60  * The state of the ringbuffer.
       
    61  */
       
    62 typedef enum {
       
    63   GST_RING_BUFFER_STATE_STOPPED,
       
    64   GST_RING_BUFFER_STATE_PAUSED,
       
    65   GST_RING_BUFFER_STATE_STARTED
       
    66 } GstRingBufferState;
       
    67 
       
    68 /**
       
    69  * GstRingBufferSegState:
       
    70  * @GST_SEGSTATE_INVALID: The content of the segment is invalid
       
    71  * @GST_SEGSTATE_EMPTY: The segment is empty
       
    72  * @GST_SEGSTATE_FILLED: The segment contains valid data
       
    73  * @GST_SEGSTATE_PARTIAL: The segment partially contains valid data
       
    74  *
       
    75  * The state of a segment in the ringbuffer.
       
    76  */
       
    77 typedef enum {
       
    78   GST_SEGSTATE_INVALID,
       
    79   GST_SEGSTATE_EMPTY,
       
    80   GST_SEGSTATE_FILLED,
       
    81   GST_SEGSTATE_PARTIAL
       
    82 } GstRingBufferSegState;
       
    83 
       
    84 /**
       
    85  * GstBufferFormatType:
       
    86  * @GST_BUFTYPE_LINEAR: samples in linear PCM
       
    87  * @GST_BUFTYPE_FLOAT: samples in float 
       
    88  * @GST_BUFTYPE_MU_LAW: samples in mulaw
       
    89  * @GST_BUFTYPE_A_LAW: samples in alaw
       
    90  * @GST_BUFTYPE_IMA_ADPCM: samples in ima adpcm
       
    91  * @GST_BUFTYPE_MPEG: samples in mpeg audio format
       
    92  * @GST_BUFTYPE_GSM: samples in gsm format
       
    93  * @GST_BUFTYPE_IEC958: samples in IEC958 frames (e.g. AC3)
       
    94  * @GST_BUFTYPE_AC3: samples in AC3 format
       
    95  * @GST_BUFTYPE_EAC3: samples in EAC3 format
       
    96  * @GST_BUFTYPE_DTS: samples in DTS format
       
    97  *
       
    98  * The format of the samples in the ringbuffer.
       
    99  */
       
   100 typedef enum
       
   101 {
       
   102   GST_BUFTYPE_LINEAR,
       
   103   GST_BUFTYPE_FLOAT,
       
   104   GST_BUFTYPE_MU_LAW,
       
   105   GST_BUFTYPE_A_LAW,
       
   106   GST_BUFTYPE_IMA_ADPCM,
       
   107   GST_BUFTYPE_MPEG,
       
   108   GST_BUFTYPE_GSM,
       
   109   GST_BUFTYPE_IEC958,
       
   110   GST_BUFTYPE_AC3,
       
   111   GST_BUFTYPE_EAC3,
       
   112   GST_BUFTYPE_DTS
       
   113 } GstBufferFormatType;
       
   114 
       
   115 typedef enum
       
   116 {
       
   117   GST_UNKNOWN,
       
   118 
       
   119   GST_S8,
       
   120   GST_U8,
       
   121 
       
   122   GST_S16_LE,
       
   123   GST_S16_BE,
       
   124   GST_U16_LE,
       
   125   GST_U16_BE,
       
   126 
       
   127   GST_S24_LE,
       
   128   GST_S24_BE,
       
   129   GST_U24_LE,
       
   130   GST_U24_BE,
       
   131 
       
   132   GST_S32_LE,
       
   133   GST_S32_BE,
       
   134   GST_U32_LE,
       
   135   GST_U32_BE,
       
   136 
       
   137   GST_S24_3LE,
       
   138   GST_S24_3BE,
       
   139   GST_U24_3LE,
       
   140   GST_U24_3BE,
       
   141   GST_S20_3LE,
       
   142   GST_S20_3BE,
       
   143   GST_U20_3LE,
       
   144   GST_U20_3BE,
       
   145   GST_S18_3LE,
       
   146   GST_S18_3BE,
       
   147   GST_U18_3LE,
       
   148   GST_U18_3BE,
       
   149 
       
   150   GST_FLOAT32_LE,
       
   151   GST_FLOAT32_BE,
       
   152 
       
   153   GST_FLOAT64_LE,
       
   154   GST_FLOAT64_BE,
       
   155 
       
   156   GST_MU_LAW,
       
   157   GST_A_LAW,
       
   158   GST_IMA_ADPCM,
       
   159   GST_MPEG,
       
   160   GST_GSM,
       
   161   GST_IEC958,
       
   162   GST_AC3,
       
   163   GST_EAC3,
       
   164   GST_DTS
       
   165 } GstBufferFormat;
       
   166 
       
   167 /**
       
   168  * GstRingBufferSpec:
       
   169  * @caps: The caps that generated the Spec.
       
   170  * @type: the sample type
       
   171  * @format: the sample format
       
   172  * @sign: the sample sign
       
   173  * @bigend: the endianness of the samples
       
   174  * @width: the width of the samples
       
   175  * @depth: th depth of the samples
       
   176  * @rate: the samplerate
       
   177  * @channels: the number of channels
       
   178  * @latency_time: the latency in microseconds
       
   179  * @buffer_time: the total buffer size in microseconds
       
   180  * @segsize: the size of one segment in bytes
       
   181  * @segtotal: the total number of segments
       
   182  * @bytes_per_sample: number of bytes in one sample
       
   183  * @silence_sample: bytes representing one sample of silence
       
   184  *
       
   185  * The structure containing the format specification of the ringbuffer.
       
   186  */
       
   187 struct _GstRingBufferSpec
       
   188 {
       
   189   /*< public >*/
       
   190   /* in */
       
   191   GstCaps  *caps;               /* the caps of the buffer */
       
   192 
       
   193   /* in/out */
       
   194   GstBufferFormatType   type;
       
   195   GstBufferFormat format;
       
   196   gboolean  sign;
       
   197   gboolean  bigend;
       
   198   gint      width;
       
   199   gint      depth;
       
   200   gint      rate;
       
   201   gint      channels;
       
   202   
       
   203   guint64  latency_time;        /* the required/actual latency time */
       
   204   guint64  buffer_time;         /* the required/actual time of the buffer */
       
   205   gint     segsize;             /* size of one buffer segment in bytes */
       
   206   gint     segtotal;            /* total number of segments */
       
   207 
       
   208   /* out */
       
   209   gint     bytes_per_sample;    /* number of bytes of one sample */
       
   210   guint8   silence_sample[32];  /* bytes representing silence */
       
   211 
       
   212   /*< private >*/
       
   213   gpointer _gst_reserved[GST_PADDING];
       
   214 };
       
   215 
       
   216 #define GST_RING_BUFFER_GET_COND(buf) (((GstRingBuffer *)buf)->cond)
       
   217 #define GST_RING_BUFFER_WAIT(buf)     (g_cond_wait (GST_RING_BUFFER_GET_COND (buf), GST_OBJECT_GET_LOCK (buf)))
       
   218 #define GST_RING_BUFFER_SIGNAL(buf)   (g_cond_signal (GST_RING_BUFFER_GET_COND (buf)))
       
   219 #define GST_RING_BUFFER_BROADCAST(buf)(g_cond_broadcast (GST_RING_BUFFER_GET_COND (buf)))
       
   220 
       
   221 /**
       
   222  * GstRingBuffer:
       
   223  * @cond: used to signal start/stop/pause/resume actions
       
   224  * @open: boolean indicating that the ringbuffer is open
       
   225  * @acquired: boolean indicating that the ringbuffer is acquired
       
   226  * @data: data in the ringbuffer
       
   227  * @spec: format and layout of the ringbuffer data
       
   228  * @segstate: status of each segment in the ringbuffer (unused)
       
   229  * @samples_per_seg: number of samples in one segment
       
   230  * @empty_seg: pointer to memory holding one segment of silence samples
       
   231  * @state: state of the buffer
       
   232  * @segdone: readpointer in the ringbuffer
       
   233  * @segbase: segment corresponding to segment 0 (unused)
       
   234  * @waiting: is a reader or writer waiting for a free segment
       
   235  *
       
   236  * The ringbuffer base class structure.
       
   237  */
       
   238 struct _GstRingBuffer {
       
   239   GstObject              object;
       
   240 
       
   241   /*< public >*/ /* with LOCK */
       
   242   GCond                 *cond;
       
   243   gboolean               open;
       
   244   gboolean               acquired;
       
   245   GstBuffer             *data;
       
   246   GstRingBufferSpec      spec;
       
   247   GstRingBufferSegState *segstate;
       
   248   gint                   samples_per_seg;
       
   249   guint8                *empty_seg;
       
   250 
       
   251   /*< public >*/ /* ATOMIC */
       
   252   gint                   state;
       
   253   gint                   segdone;
       
   254   gint                   segbase;
       
   255   gint                   waiting;
       
   256 
       
   257   /*< private >*/
       
   258   GstRingBufferCallback  callback;
       
   259   gpointer               cb_data;
       
   260 
       
   261   /*< private >*/
       
   262   union {
       
   263     struct {
       
   264       gboolean           flushing;
       
   265       /* ATOMIC */
       
   266       gint               may_start;
       
   267     } ABI;
       
   268     /* adding + 0 to mark ABI change to be undone later */
       
   269     gpointer _gst_reserved[GST_PADDING + 0];
       
   270   } abidata;
       
   271 };
       
   272 
       
   273 /**
       
   274  * GstRingBufferClass:
       
   275  * @open_device:  open the device, don't set any params or allocate anything
       
   276  * @acquire: allocate the resources for the ringbuffer using the given spec
       
   277  * @release: free resources of the ringbuffer
       
   278  * @close_device: close the device
       
   279  * @start: start processing of samples
       
   280  * @pause: pause processing of samples
       
   281  * @resume: resume processing of samples after pause
       
   282  * @stop: stop processing of samples
       
   283  * @delay: get number of samples queued in device
       
   284  *
       
   285  * The vmethods that subclasses can override to implement the ringbuffer.
       
   286  */
       
   287 struct _GstRingBufferClass {
       
   288   GstObjectClass parent_class;
       
   289 
       
   290   /*< public >*/
       
   291   gboolean     (*open_device)  (GstRingBuffer *buf);
       
   292   gboolean     (*acquire)      (GstRingBuffer *buf, GstRingBufferSpec *spec);
       
   293   gboolean     (*release)      (GstRingBuffer *buf);
       
   294   gboolean     (*close_device) (GstRingBuffer *buf);
       
   295 
       
   296   gboolean     (*start)        (GstRingBuffer *buf);
       
   297   gboolean     (*pause)        (GstRingBuffer *buf);
       
   298   gboolean     (*resume)       (GstRingBuffer *buf);
       
   299   gboolean     (*stop)         (GstRingBuffer *buf);
       
   300 
       
   301   guint        (*delay)        (GstRingBuffer *buf);
       
   302 
       
   303   /*< private >*/
       
   304   gpointer _gst_reserved[GST_PADDING];
       
   305 };
       
   306 #ifdef __SYMBIAN32__
       
   307 IMPORT_C
       
   308 #endif
       
   309 
       
   310 
       
   311 GType gst_ring_buffer_get_type(void);
       
   312 
       
   313 /* callback stuff */
       
   314 #ifdef __SYMBIAN32__
       
   315 IMPORT_C
       
   316 #endif
       
   317 
       
   318 void            gst_ring_buffer_set_callback    (GstRingBuffer *buf, GstRingBufferCallback cb, 
       
   319                                                  gpointer user_data);
       
   320 #ifdef __SYMBIAN32__
       
   321 IMPORT_C
       
   322 #endif
       
   323 
       
   324 
       
   325 gboolean        gst_ring_buffer_parse_caps      (GstRingBufferSpec *spec, GstCaps *caps);
       
   326 #ifdef __SYMBIAN32__
       
   327 IMPORT_C
       
   328 #endif
       
   329 
       
   330 void            gst_ring_buffer_debug_spec_caps (GstRingBufferSpec *spec);
       
   331 #ifdef __SYMBIAN32__
       
   332 IMPORT_C
       
   333 #endif
       
   334 
       
   335 void            gst_ring_buffer_debug_spec_buff (GstRingBufferSpec *spec);
       
   336 
       
   337 /* device state */
       
   338 #ifdef __SYMBIAN32__
       
   339 IMPORT_C
       
   340 #endif
       
   341 
       
   342 gboolean        gst_ring_buffer_open_device     (GstRingBuffer *buf);
       
   343 #ifdef __SYMBIAN32__
       
   344 IMPORT_C
       
   345 #endif
       
   346 
       
   347 gboolean        gst_ring_buffer_close_device    (GstRingBuffer *buf);
       
   348 #ifdef __SYMBIAN32__
       
   349 IMPORT_C
       
   350 #endif
       
   351 
       
   352 
       
   353 gboolean        gst_ring_buffer_device_is_open  (GstRingBuffer *buf);
       
   354 
       
   355 /* allocate resources */
       
   356 #ifdef __SYMBIAN32__
       
   357 IMPORT_C
       
   358 #endif
       
   359 
       
   360 gboolean        gst_ring_buffer_acquire         (GstRingBuffer *buf, GstRingBufferSpec *spec);
       
   361 #ifdef __SYMBIAN32__
       
   362 IMPORT_C
       
   363 #endif
       
   364 
       
   365 gboolean        gst_ring_buffer_release         (GstRingBuffer *buf);
       
   366 #ifdef __SYMBIAN32__
       
   367 IMPORT_C
       
   368 #endif
       
   369 
       
   370 
       
   371 gboolean        gst_ring_buffer_is_acquired     (GstRingBuffer *buf);
       
   372 
       
   373 /* flushing */
       
   374 #ifdef __SYMBIAN32__
       
   375 IMPORT_C
       
   376 #endif
       
   377 
       
   378 void            gst_ring_buffer_set_flushing    (GstRingBuffer *buf, gboolean flushing);
       
   379 
       
   380 /* playback/pause */
       
   381 #ifdef __SYMBIAN32__
       
   382 IMPORT_C
       
   383 #endif
       
   384 
       
   385 gboolean        gst_ring_buffer_start           (GstRingBuffer *buf);
       
   386 #ifdef __SYMBIAN32__
       
   387 IMPORT_C
       
   388 #endif
       
   389 
       
   390 gboolean        gst_ring_buffer_pause           (GstRingBuffer *buf);
       
   391 #ifdef __SYMBIAN32__
       
   392 IMPORT_C
       
   393 #endif
       
   394 
       
   395 gboolean        gst_ring_buffer_stop            (GstRingBuffer *buf);
       
   396 
       
   397 /* get status */
       
   398 #ifdef __SYMBIAN32__
       
   399 IMPORT_C
       
   400 #endif
       
   401 
       
   402 guint           gst_ring_buffer_delay           (GstRingBuffer *buf);
       
   403 #ifdef __SYMBIAN32__
       
   404 IMPORT_C
       
   405 #endif
       
   406 
       
   407 guint64         gst_ring_buffer_samples_done    (GstRingBuffer *buf);
       
   408 #ifdef __SYMBIAN32__
       
   409 IMPORT_C
       
   410 #endif
       
   411 
       
   412 
       
   413 void            gst_ring_buffer_set_sample      (GstRingBuffer *buf, guint64 sample);
       
   414 
       
   415 /* clear all segments */
       
   416 #ifdef __SYMBIAN32__
       
   417 IMPORT_C
       
   418 #endif
       
   419 
       
   420 void            gst_ring_buffer_clear_all       (GstRingBuffer *buf);
       
   421 
       
   422 /* commit samples */
       
   423 #ifdef __SYMBIAN32__
       
   424 IMPORT_C
       
   425 #endif
       
   426 
       
   427 guint           gst_ring_buffer_commit          (GstRingBuffer *buf, guint64 sample, 
       
   428                                                  guchar *data, guint len);
       
   429 #ifdef __SYMBIAN32__
       
   430 IMPORT_C
       
   431 #endif
       
   432 
       
   433 guint           gst_ring_buffer_commit_full     (GstRingBuffer * buf, guint64 *sample,
       
   434 		                                 guchar * data, gint in_samples, 
       
   435 						 gint out_samples, gint * accum);
       
   436 
       
   437 /* read samples */
       
   438 #ifdef __SYMBIAN32__
       
   439 IMPORT_C
       
   440 #endif
       
   441 
       
   442 guint           gst_ring_buffer_read            (GstRingBuffer *buf, guint64 sample, 
       
   443                                                  guchar *data, guint len);
       
   444 
       
   445 /* mostly protected */
       
   446 /* not yet implemented
       
   447 gboolean        gst_ring_buffer_prepare_write   (GstRingBuffer *buf, gint *segment, guint8 **writeptr, gint *len);
       
   448 */
       
   449 #ifdef __SYMBIAN32__
       
   450 IMPORT_C
       
   451 #endif
       
   452 
       
   453 gboolean        gst_ring_buffer_prepare_read    (GstRingBuffer *buf, gint *segment, guint8 **readptr, gint *len);
       
   454 #ifdef __SYMBIAN32__
       
   455 IMPORT_C
       
   456 #endif
       
   457 
       
   458 void            gst_ring_buffer_clear           (GstRingBuffer *buf, gint segment);
       
   459 #ifdef __SYMBIAN32__
       
   460 IMPORT_C
       
   461 #endif
       
   462 
       
   463 void            gst_ring_buffer_advance         (GstRingBuffer *buf, guint advance);
       
   464 #ifdef __SYMBIAN32__
       
   465 IMPORT_C
       
   466 #endif
       
   467 
       
   468 
       
   469 void            gst_ring_buffer_may_start       (GstRingBuffer *buf, gboolean allowed);
       
   470 
       
   471 
       
   472 G_END_DECLS
       
   473 
       
   474 #endif /* __GST_RING_BUFFER_H__ */