6fd9434c416cb766f45618da749df554ade45558
[maemo-recorder] / src / maemo-recorder.h
1 /* vim: set ts=4 sw=4 et: */
2 /*
3  * maemo-recorder.h
4  *
5  * Copyright (C) 2006 Nokia Corporation
6  *
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License version 2 as
10  * published by the Free Software Foundation.
11  *
12  * This program is distributed in the hope that it will be useful, but
13  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
14  * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15  * for more details.
16  *
17  * You should have received a copy of the GNU General Public License along
18  * with this program; if not, write to the Free Software Foundation, Inc.,
19  * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20  *
21  */
22
23 #ifndef _MAEMO_RECORDER_H_
24 #define _MAEMO_RECORDER_H_
25
26 #include <libosso.h>
27 #include <osso-log.h>
28 #include <hildon-widgets/hildon-program.h>
29 #include <hildon-widgets/hildon-window.h>
30 #include <gconf/gconf-client.h>
31
32 #include <gtk/gtk.h>
33 #include <gst/gst.h>
34 #include <sys/time.h>
35
36 #define SERVICE_NAME "maemo_recorder"
37 #define SERVICE_NAME_FULL "com.nokia.maemo_recorder"
38
39 #define DEFAULT_CHANNELS 1
40 #define DEFAULT_RATE 8000
41
42 #define GST_TYPE_ILBC "audio/x-iLBC"
43 #define ILBC_RATE DEFAULT_RATE
44
45 /* 
46  * 15.2 kbps (SI kilo) for 20 ms frames
47  * 38 bytes / frame, 50 frames / sec 
48  */
49 /* 13.33 kbps for 30 ms frames */
50 #define ILBC_BITRATE_20 15200
51 /* 8000 Hz * 8 bits/sample */
52 #define PCMA_BITRATE 64000
53 #define PCMU_BITRATE 64000
54
55 #define GST_TYPE_PCMA "audio/x-alaw"
56 #define GST_TYPE_PCMU "audio/x-mulaw"
57 #define GST_TYPE_PCM "audio/x-raw-int"
58 #define PCM_RATE 8000
59 #define PCM_WIDTH 16
60 #define PCM_DEPTH 16
61 #define PCM_ENDIANNESS 1234
62
63 typedef enum
64 {
65     APPSTATE_READY = 1,
66     APPSTATE_PLAYING,
67     APPSTATE_RECORDING
68 } AppState;
69
70 typedef enum
71 {
72     FORMAT_NONE = 0,
73     FORMAT_PCM,
74     FORMAT_PCMA,
75     FORMAT_PCMU,
76     FORMAT_ILBC,
77     FORMAT_MP3,
78     FORMAT_WAV
79 } AudioFormat;
80
81 #define FORMAT_NAME_WAV "WAV"
82 #define FORMAT_NAME_PCMA "PCM A-law"
83 #define FORMAT_NAME_PCMU "PCM \u03BC-law"
84 /*
85 #define FORMAT_NAME_PCMU "PCM mu-law"
86 */
87 #define FORMAT_NAME_PCM "PCM raw"
88 #define FORMAT_NAME_ILBC "iLBC"
89
90 /* TODO: this kind of struct might be more handy when passing around audioformat info */
91 #if 0
92 struct _AudioFormatSpec
93 {
94     AudioFormat format;
95     gchar *mime_type;
96     gint rate;
97     gint channels;
98     gint width;
99     gint depth;
100     gint endianness;
101     gint frame_len;
102     gint frame_size;
103 };
104
105 typedef struct _AudioFormatSpec AudioFormatSpec;
106 #endif
107
108 typedef enum
109 {
110     TYPE_FILE = 0,
111     TYPE_STREAM = 1
112 } PipeMode;
113
114 typedef struct _mainViewStr
115 {
116     GtkWidget *toolBar;
117     GtkWidget *fileNameEntry;
118     GtkWidget *lengthEntry;
119     GtkWidget *stateEntry;
120     GtkWidget *formatEntry;
121     GtkObject *adjustment;
122
123 } mainViewStr;
124
125 typedef struct _AppDataStr
126 {
127     HildonProgram *app;
128     HildonWindow *mainView;
129
130     mainViewStr mainViewData;
131
132     /* gstreamer components */
133     GstElement *pipeline;
134     GstElement *recPipeline;
135     GstElement *playPipeline;
136     GstElement *queue;
137     gint playPipelineType;
138
139     osso_context_t *osso;
140     GConfClient *gconf_client;
141
142     gchar * openFileName;
143     gchar * saveFileName;
144     gboolean saved;
145
146     AudioFormat filter;      /* selected recording format */
147     AudioFormat file_format; /* format of the recorded file or file currently open */
148     PipeMode type;
149     GtkWidget* radio_pcma;
150     GtkWidget* radio_ilbc;
151     GtkWidget* radio_pcm;          
152     GtkWidget* radiotype;
153     AppState state;
154
155     GtkWidget *buttonSave;
156     GtkWidget *buttonSaveAs;
157     GtkWidget *buttonPlay;
158     GtkWidget *buttonRec;
159
160     struct timeval recStartTv; /* timeval when recording started */
161     guint recUpdateId;     /* g_source_id for rec update timeout func */
162     gchar *mimeURI;        /* uri to open via mime cb */
163
164 } AppData;
165
166 void setAppState(AppData *app, AppState state);
167 AppState getAppState(AppData *app);
168
169 #if 0
170 AudioFormatSpec * audio_format_spec_new(void);
171 void audio_format_spec_free(AudioFormatSpec *af);
172 #endif
173
174 #endif /* _MAEMO_RECORDER_H_ */