• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * GStreamer
3  * Copyright (C) 2013 Fluendo S.L. <support@fluendo.com>
4  *    Authors: Andoni Morales Alastruey <amorales@fluendo.com>
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Library General Public
8  * License as published by the Free Software Foundation; either
9  * version 2 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * Library General Public License for more details.
15  *
16  * You should have received a copy of the GNU Library General Public
17  * License along with this library; if not, write to the
18  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19  * Boston, MA 02111-1307, USA.
20  */
21 
22 #ifndef __GST_AVF_ASSET_SRC_H__
23 #define __GST_AVF_ASSET_SRC_H__
24 
25 #ifdef HAVE_CONFIG_H
26 #  include "config.h"
27 #endif
28 
29 #include <gst/gst.h>
30 #include <gst/base/base.h>
31 #include <gst/audio/audio.h>
32 #import <AVFoundation/AVFoundation.h>
33 #import <AVFoundation/AVAssetReader.h>
34 #import <AVFoundation/AVAssetReaderOutput.h>
35 
36 G_BEGIN_DECLS
37 
38 #define GST_TYPE_AVF_ASSET_SRC \
39   (gst_avf_asset_src_get_type())
40 #define GST_AVF_ASSET_SRC_READER(obj) \
41   ((__bridge GstAVFAssetReader *)(obj->reader))
42 #define GST_AVF_ASSET_SRC(obj) \
43   (G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_AVF_ASSET_SRC,GstAVFAssetSrc))
44 #define GST_AVF_ASSET_SRC_CLASS(klass) \
45   (G_TYPE_CHECK_CLASS_CAST((klass),GST_TYPE_AVF_ASSET_SRC,GstAVFAssetSrcClass))
46 #define GST_IS_AVF_ASSET_SRC(obj) \
47   (G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_AVF_ASSET_SRC))
48 #define GST_IS_AVF_ASSET_SRC_CLASS(klass) \
49   (G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_AVF_ASSET_SRC))
50 #define GST_AVF_ASSET_SRC_ERROR gst_avf_asset_src_error_quark ()
51 
52 typedef struct _GstAVFAssetSrc      GstAVFAssetSrc;
53 typedef struct _GstAVFAssetSrcClass GstAVFAssetSrcClass;
54 
55 typedef enum
56 {
57   GST_AVF_ASSET_READER_MEDIA_TYPE_AUDIO,
58   GST_AVF_ASSET_READER_MEDIA_TYPE_VIDEO,
59 } GstAVFAssetReaderMediaType;
60 
61 typedef enum
62 {
63   GST_AVF_ASSET_ERROR_NOT_PLAYABLE,
64   GST_AVF_ASSET_ERROR_INIT,
65   GST_AVF_ASSET_ERROR_START,
66   GST_AVF_ASSET_ERROR_READ,
67 } GstAVFAssetError;
68 
69 typedef enum
70 {
71   GST_AVF_ASSET_SRC_STATE_STOPPED,
72   GST_AVF_ASSET_SRC_STATE_STARTED,
73   GST_AVF_ASSET_SRC_STATE_READING,
74 } GstAVFAssetSrcState;
75 
76 @interface GstAVFAssetReader: NSObject
77 {
78   AVAsset *asset;
79   AVAssetReader *reader;
80   AVAssetReaderTrackOutput *video_track;
81   AVAssetReaderTrackOutput *audio_track;
82   NSArray *audio_tracks;
83   NSArray *video_tracks;
84   int selected_audio_track;
85   int selected_video_track;
86   GstCaps *audio_caps;
87   GstCaps *video_caps;
88   gboolean reading;
89   GstClockTime duration;
90   GstClockTime position;
91 }
92 
93 @property GstClockTime duration;
94 @property GstClockTime position;
95 
96 - (id) initWithURI:(gchar*) uri : (GError **) error;
97 - (void) start : (GError **) error;
98 - (void) stop;
99 - (void) seekTo: (guint64) start : (guint64) stop : (GError **) error;
100 - (BOOL) hasMediaType: (GstAVFAssetReaderMediaType) type;
101 - (GstCaps *) getCaps: (GstAVFAssetReaderMediaType) type;
102 - (BOOL) selectTrack: (GstAVFAssetReaderMediaType) type : (gint) index;
103 - (GstBuffer *) nextBuffer:  (GstAVFAssetReaderMediaType) type : (GError **) error;
104 @end
105 
106 struct _GstAVFAssetSrc
107 {
108   GstElement element;
109 
110   GstPad *videopad;
111   GstPad *audiopad;
112   gint selected_video_track;
113   gint selected_audio_track;
114 
115   /* NOTE: ARC no longer allows Objective-C pointers in structs. */
116   /* Instead, use gpointer with explicit __bridge_* calls */
117   gpointer reader;
118 
119   GstAVFAssetSrcState state;
120   GMutex lock;
121   GstEvent *seek_event;
122 
123   GstFlowReturn last_audio_pad_ret;
124   GstFlowReturn last_video_pad_ret;
125 
126   /* Properties */
127   gchar * uri;
128 };
129 
130 struct _GstAVFAssetSrcClass
131 {
132   GstElementClass parent_class;
133 };
134 
135 GType gst_avf_asset_src_get_type (void);
136 
137 G_END_DECLS
138 
139 #endif /* __GST_AVF_ASSET_SRC_H__ */
140