cleanups
[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/hildon-program.h>
29 #include <hildon/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 22050
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 #define ILBC_BITRATE_30 13300
52
53 /* 8000 Hz * 8 bits/sample */
54 #define PCMA_BITRATE 64000
55 #define PCMU_BITRATE 64000
56
57 #define GST_TYPE_PCMA "audio/x-alaw"
58 #define GST_TYPE_PCMU "audio/x-mulaw"
59 #define GST_TYPE_PCM "audio/x-raw-int"
60 #define PCM_RATE 22050
61 #define PCM_WIDTH 16
62 #define PCM_DEPTH 16
63 #define PCM_ENDIANNESS 1234
64
65 typedef enum
66 {
67     APPSTATE_READY = 1,
68     APPSTATE_PLAYING,
69     APPSTATE_RECORDING,
70     APPSTATE_PAUSED
71 } AppState;
72
73 typedef enum
74 {
75     FORMAT_NONE = 0,
76     FORMAT_PCM,
77     FORMAT_PCMA,
78     FORMAT_PCMU,
79     FORMAT_ILBC,
80     FORMAT_MP3,
81     FORMAT_WAV
82 } AudioFormat;
83
84 #define FORMAT_NAME_WAV "WAV"
85 #define FORMAT_NAME_PCMA "PCM A-law"
86 #define FORMAT_NAME_PCMU "PCM \u03BC-law"
87 /*
88 #define FORMAT_NAME_PCMU "PCM mu-law"
89 */
90 #define FORMAT_NAME_PCM "PCM raw"
91 #define FORMAT_NAME_ILBC "iLBC"
92
93 #define PLAY_ICON "/usr/share/pixmaps/recorder/play.png"
94 #define REC_ICON "/usr/share/pixmaps/recorder/record.png"
95 #define STOP_ICON "/usr/share/pixmaps/recorder/stop.png"
96
97 #define DEFAULT_TMP_DIR "/home/user/MyDocs/.recorder"
98
99 /* TODO: this kind of struct might be more handy when passing around audioformat info */
100 #if 0
101 struct _AudioFormatSpec
102 {
103     AudioFormat format;
104     gchar *mime_type;
105     gint rate;
106     gint channels;
107     gint width;
108     gint depth;
109     gint endianness;
110     gint frame_len;
111     gint frame_size;
112 };
113
114 typedef struct _AudioFormatSpec AudioFormatSpec;
115 #endif
116
117 typedef enum
118 {
119     TYPE_FILE = 0,
120     TYPE_STREAM = 1
121 } PipeMode;
122
123 typedef struct _mainViewStr
124 {
125     GtkWidget *toolBar;
126     GtkWidget *fileNameEntry;
127     GtkWidget *lengthEntry;
128     GtkWidget *stateEntry;
129     GtkWidget *formatEntry;
130     GtkObject *adjustment;
131     GtkWidget *ctime;
132 } mainViewStr;
133
134 typedef struct _AppDataStr
135 {
136     HildonProgram *app;
137     HildonWindow *mainView;
138
139     mainViewStr mainViewData;
140
141     /* gstreamer components */
142     GstElement *pipeline;
143     GstElement *recPipeline;
144     GstElement *playPipeline;
145     GstElement *queue;
146     gint playPipelineType;
147
148     osso_context_t *osso;
149     GConfClient *gconf_client;
150
151     gchar * openFileName;
152     gchar * saveFileName;
153     gboolean saved;
154
155     AudioFormat filter;      /* selected recording format */
156     AudioFormat file_format; /* format of the recorded file or file currently open */
157     PipeMode type;
158     GtkWidget* radio_pcma;
159     GtkWidget* radio_ilbc;
160     GtkWidget* radio_pcm;          
161     GtkWidget* radiotype;
162     AppState state;
163
164     GtkWidget *buttonSave;
165     GtkWidget *buttonSaveAs;
166     GtkWidget *buttonPlay;
167     GtkWidget *buttonRec;
168
169     guint recUpdateId;     /* g_source_id for rec update timeout func */
170     gchar *mimeURI;        /* uri to open via mime cb */
171     gdouble rectime;
172 } AppData;
173
174 void setAppState(AppData *app, AppState state);
175 AppState getAppState(AppData *app);
176
177 #if 0
178 AudioFormatSpec * audio_format_spec_new(void);
179 void audio_format_spec_free(AudioFormatSpec *af);
180 #endif
181
182 #endif /* _MAEMO_RECORDER_H_ */