~ubuntu-branches/ubuntu/utopic/libhybris/utopic-proposed

« back to all changes in this revision

Viewing changes to debian/patches/debian-changes

  • Committer: Package Import Robot
  • Author(s): Ricardo Salveti de Araujo, Jim Hodapp, Ricardo Salveti de Araujo
  • Date: 2014-06-24 11:42:07 UTC
  • Revision ID: package-import@ubuntu.com-20140624114207-tnxrlboiv48dkdv6
Tags: 0.1.0+git20131207+e452e83-0ubuntu18
[ Jim Hodapp ]
* compat: adding camera_service, also exporting the media_recorder
  functionality

[ Ricardo Salveti de Araujo ]
* Makefile.am: installing additional header for media_recorder
* debian/control: bumping standards-version to 3.9.5

Show diffs side-by-side

added added

removed removed

Lines of Context:
30
30
 
31
31
 HYBRIS_PATH := $(LOCAL_PATH)/../../hybris
32
32
 
 
33
@@ -43,6 +44,7 @@ LOCAL_SHARED_LIBRARIES := \
 
34
        libis_compat_layer \
 
35
        libsf_compat_layer \
 
36
        libcamera_compat_layer \
 
37
+       libmedia_compat_layer \
 
38
        libcutils \
 
39
        libcamera_client \
 
40
        libutils \
33
41
--- libhybris-0.1.0+git20131207+e452e83.orig/compat/camera/camera_compatibility_layer.cpp
34
42
+++ libhybris-0.1.0+git20131207+e452e83/compat/camera/camera_compatibility_layer.cpp
35
 
@@ -27,17 +27,25 @@
 
43
@@ -17,6 +17,8 @@
 
44
  *              Ricardo Salveti de Araujo <ricardo.salveti@canonical.com>
 
45
  */
 
46
 
 
47
+#define LOG_NDEBUG 0
 
48
+
 
49
 #include <hybris/internal/camera_control.h>
 
50
 #include <hybris/camera/camera_compatibility_layer.h>
 
51
 #include <hybris/camera/camera_compatibility_layer_capabilities.h>
 
52
@@ -27,17 +29,25 @@
36
53
 #include <binder/ProcessState.h>
37
54
 #include <camera/Camera.h>
38
55
 #include <camera/CameraParameters.h>
59
76
 void CameraControl::onFrameAvailable()
60
77
 {
61
78
        REPORT_FUNCTION();
62
 
@@ -170,7 +178,11 @@ CameraControl* android_camera_connect_to
 
79
@@ -170,7 +180,11 @@ CameraControl* android_camera_connect_to
63
80
 
64
81
        CameraControl* cc = new CameraControl();
65
82
        cc->listener = listener;
71
88
 
72
89
        if (cc->camera == NULL)
73
90
                return NULL;
74
 
@@ -511,30 +523,57 @@ void android_camera_set_preview_texture(
 
91
@@ -511,30 +525,57 @@ void android_camera_set_preview_texture(
75
92
        assert(control);
76
93
 
77
94
        static const bool allow_synchronous_mode = false;
129
146
 void android_camera_set_preview_surface(CameraControl* control, SfSurface* surface)
130
147
 {
131
148
        REPORT_FUNCTION();
132
 
@@ -544,6 +583,7 @@ void android_camera_set_preview_surface(
 
149
@@ -544,6 +585,7 @@ void android_camera_set_preview_surface(
133
150
        android::Mutex::Autolock al(control->guard);
134
151
        control->camera->setPreviewDisplay(surface->surface);
135
152
 }
137
154
 
138
155
 void android_camera_start_preview(CameraControl* control)
139
156
 {
 
157
--- libhybris-0.1.0+git20131207+e452e83.orig/compat/camera/direct_camera_test.cpp
 
158
+++ libhybris-0.1.0+git20131207+e452e83/compat/camera/direct_camera_test.cpp
 
159
@@ -1,11 +1,11 @@
 
160
 /*
 
161
- * Copyright (C) 2013 Canonical Ltd
 
162
+ * Copyright (C) 2013-2014 Canonical Ltd
 
163
  *
 
164
  * Licensed under the Apache License, Version 2.0 (the "License");
 
165
  * you may not use this file except in compliance with the License.
 
166
  * You may obtain a copy of the License at
 
167
  *
 
168
- *      http://www.apache.org/licenses/LICENSE-2.0
 
169
+ *             http://www.apache.org/licenses/LICENSE-2.0
 
170
  *
 
171
  * Unless required by applicable law or agreed to in writing, software
 
172
  * distributed under the License is distributed on an "AS IS" BASIS,
 
173
@@ -14,11 +14,13 @@
 
174
  * limitations under the License.
 
175
  *
 
176
  * Authored by: Thomas Voß <thomas.voss@canonical.com>
 
177
- *              Ricardo Salveti de Araujo <ricardo.salveti@canonical.com>
 
178
+ *                             Ricardo Salveti de Araujo <ricardo.salveti@canonical.com>
 
179
+ *                             Jim Hodapp <jim.hodapp@canonical.com>
 
180
  */
 
181
 
 
182
 #include <hybris/camera/camera_compatibility_layer.h>
 
183
 #include <hybris/camera/camera_compatibility_layer_capabilities.h>
 
184
+#include <hybris/media/media_recorder_layer.h>
 
185
 
 
186
 #include <hybris/input/input_stack_compatibility_layer.h>
 
187
 #include <hybris/input/input_stack_compatibility_layer_codes_key.h>
 
188
@@ -45,6 +47,10 @@
 
189
 int shot_counter = 1;
 
190
 int32_t current_zoom_level = 1;
 
191
 bool new_camera_frame_available = true;
 
192
+static CameraControl* camera_control = NULL;
 
193
+int camera_width = 0, camera_height = 0;
 
194
+static MediaRecorderWrapper *recorder = NULL;
 
195
+bool recording = false;
 
196
 
 
197
 EffectMode next_effect()
 
198
 {
 
199
@@ -122,7 +128,7 @@ void jpeg_data_cb(void* data, uint32_t d
 
200
        printf("%s: %d \n", __PRETTY_FUNCTION__, data_size);
 
201
 
 
202
        char fn[256];
 
203
-       sprintf(fn, "/data/shot_%d.jpeg", shot_counter);
 
204
+       sprintf(fn, "/cache/shot_%d.jpeg", shot_counter);
 
205
        int fd = open(fn, O_RDWR | O_CREAT, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH);
 
206
        write(fd, data, data_size);
 
207
        close(fd);
 
208
@@ -135,131 +141,43 @@ void jpeg_data_cb(void* data, uint32_t d
 
209
 void size_cb(void* ctx, int width, int height)
 
210
 {
 
211
        printf("Supported size: [%d,%d]\n", width, height);
 
212
-}
 
213
-
 
214
-void preview_texture_needs_update_cb(void* ctx)
 
215
-{
 
216
-       new_camera_frame_available = true;
 
217
-}
 
218
-
 
219
-void on_new_input_event(Event* event, void* context)
 
220
-{
 
221
-    assert(context);
 
222
-
 
223
-    if (event->type == KEY_EVENT_TYPE && event->action == ISCL_KEY_EVENT_ACTION_UP) {
 
224
-           printf("We have got a key event: %d \n", event->details.key.key_code);
 
225
-
 
226
-           CameraControl* cc = static_cast<CameraControl*>(context);
 
227
-
 
228
-           switch(event->details.key.key_code) {
 
229
-           case ISCL_KEYCODE_VOLUME_UP:
 
230
-                   printf("\tZooming in now.\n");
 
231
-                   android_camera_start_zoom(cc, current_zoom_level+1);
 
232
-                   break;
 
233
-           case ISCL_KEYCODE_VOLUME_DOWN:
 
234
-                   printf("\tZooming out now.\n");
 
235
-                   android_camera_start_zoom(cc, current_zoom_level-1);
 
236
-                   break;
 
237
-           case ISCL_KEYCODE_POWER:
 
238
-                   printf("\tTaking a photo now.\n");
 
239
-                   android_camera_take_snapshot(cc);
 
240
-                   break;
 
241
-           case ISCL_KEYCODE_HEADSETHOOK:
 
242
-                   printf("\tSwitching effect.\n");
 
243
-                   android_camera_set_effect_mode(cc, next_effect());
 
244
-           }
 
245
-    } else if (event->type == MOTION_EVENT_TYPE &&
 
246
-                   event->details.motion.pointer_count == 1) {
 
247
-           if ((event->action & ISCL_MOTION_EVENT_ACTION_MASK) == ISCL_MOTION_EVENT_ACTION_UP) {
 
248
-                   printf("\tMotion event(Action up): (%f, %f) \n",
 
249
-                                   event->details.motion.pointer_coordinates[0].x,
 
250
-                                   event->details.motion.pointer_coordinates[0].y);
 
251
-           }
 
252
-
 
253
-           if ((event->action & ISCL_MOTION_EVENT_ACTION_MASK) == ISCL_MOTION_EVENT_ACTION_DOWN) {
 
254
-                   printf("\tMotion event(Action down): (%f, %f) \n",
 
255
-                                   event->details.motion.pointer_coordinates[0].x,
 
256
-                                   event->details.motion.pointer_coordinates[0].y);
 
257
-           }
 
258
-    }
 
259
-}
 
260
-
 
261
-struct ClientWithSurface
 
262
-{
 
263
-       SfClient* client;
 
264
-       SfSurface* surface;
 
265
-};
 
266
-
 
267
-ClientWithSurface client_with_surface(bool setup_surface_with_egl)
 
268
-{
 
269
-       ClientWithSurface cs = ClientWithSurface();
 
270
-
 
271
-       cs.client = sf_client_create();
 
272
-
 
273
-       if (!cs.client) {
 
274
-               printf("Problem creating client ... aborting now.");
 
275
-               return cs;
 
276
-       }
 
277
-
 
278
-       static const size_t primary_display = 0;
 
279
-
 
280
-       SfSurfaceCreationParameters params = {
 
281
-               0,
 
282
-               0,
 
283
-               (int) sf_get_display_width(primary_display),
 
284
-               (int) sf_get_display_height(primary_display),
 
285
-               -1, //PIXEL_FORMAT_RGBA_8888,
 
286
-               15000,
 
287
-               0.5f,
 
288
-               setup_surface_with_egl, // Do not associate surface with egl, will be done by camera HAL
 
289
-               "CameraCompatLayerTestSurface"
 
290
-       };
 
291
-
 
292
-       cs.surface = sf_surface_create(cs.client, &params);
 
293
-
 
294
-       if (!cs.surface) {
 
295
-               printf("Problem creating surface ... aborting now.");
 
296
-               return cs;
 
297
+       if (width == 1024 && height == 768) {
 
298
+               camera_width = 1024;
 
299
+               camera_height = 768;
 
300
        }
 
301
-
 
302
-       sf_surface_make_current(cs.surface);
 
303
-
 
304
-       return cs;
 
305
 }
 
306
 
 
307
-#define PRINT_GLERROR() printf("GL error@%d: %x\n", __LINE__, glGetError());
 
308
-
 
309
 struct RenderData
 
310
 {
 
311
        static const char* vertex_shader()
 
312
        {
 
313
                return
 
314
-                       "#extension GL_OES_EGL_image_external : require              \n"
 
315
-                       "attribute vec4 a_position;                                  \n"
 
316
-                       "attribute vec2 a_texCoord;                                  \n"
 
317
-                       "uniform mat4 m_texMatrix;                                   \n"
 
318
-                       "varying vec2 v_texCoord;                                    \n"
 
319
-                       "varying float topDown;                                      \n"
 
320
-                       "void main()                                                 \n"
 
321
-                       "{                                                           \n"
 
322
-                       "   gl_Position = a_position;                                \n"
 
323
-                       "   v_texCoord = a_texCoord;                                 \n"
 
324
-                       //                "   v_texCoord = (m_texMatrix * vec4(a_texCoord, 0.0, 1.0)).xy;\n"
 
325
-                       //"   topDown = v_texCoord.y;                                  \n"
 
326
-                       "}                                                           \n";
 
327
+                       "#extension GL_OES_EGL_image_external : require                          \n"
 
328
+                       "attribute vec4 a_position;                                                                      \n"
 
329
+                       "attribute vec2 a_texCoord;                                                                      \n"
 
330
+                       "uniform mat4 m_texMatrix;                                                                       \n"
 
331
+                       "varying vec2 v_texCoord;                                                                        \n"
 
332
+                       "varying float topDown;                                                                          \n"
 
333
+                       "void main()                                                                                             \n"
 
334
+                       "{                                                                                                                       \n"
 
335
+                       "       gl_Position = a_position;                                                                \n"
 
336
+                       "       v_texCoord = a_texCoord;                                                                 \n"
 
337
+                       //                                "   v_texCoord = (m_texMatrix * vec4(a_texCoord, 0.0, 1.0)).xy;\n"
 
338
+                       //"   topDown = v_texCoord.y;                                                              \n"
 
339
+                       "}                                                                                                                       \n";
 
340
        }
 
341
 
 
342
        static const char* fragment_shader()
 
343
        {
 
344
                return
 
345
-                       "#extension GL_OES_EGL_image_external : require      \n"
 
346
-                       "precision mediump float;                            \n"
 
347
-                       "varying vec2 v_texCoord;                            \n"
 
348
-                       "uniform samplerExternalOES s_texture;               \n"
 
349
-                       "void main()                                         \n"
 
350
-                       "{                                                   \n"
 
351
+                       "#extension GL_OES_EGL_image_external : require          \n"
 
352
+                       "precision mediump float;                                                        \n"
 
353
+                       "varying vec2 v_texCoord;                                                        \n"
 
354
+                       "uniform samplerExternalOES s_texture;                           \n"
 
355
+                       "void main()                                                                             \n"
 
356
+                       "{                                                                                                       \n"
 
357
                        "  gl_FragColor = texture2D( s_texture, v_texCoord );\n"
 
358
-                       "}                                                   \n";
 
359
+                       "}                                                                                                       \n";
 
360
        }
 
361
 
 
362
        static GLuint loadShader(GLenum shaderType, const char* pSource)
 
363
@@ -354,6 +272,254 @@ struct RenderData
 
364
        GLint matrix_loc;
 
365
 };
 
366
 
 
367
+
 
368
+static RenderData render_data;
 
369
+static EGLDisplay disp;
 
370
+static EGLSurface surface;
 
371
+
 
372
+void preview_texture_needs_update_cb(void* ctx)
 
373
+{
 
374
+       ALOGD("Updating preview texture");
 
375
+       new_camera_frame_available = true;
 
376
+       static GLfloat vVertices[] = { 0.0f, 0.0f, 0.0f, // Position 0
 
377
+               0.0f, 0.0f, // TexCoord 0
 
378
+               0.0f, 1.0f, 0.0f, // Position 1
 
379
+               0.0f, 1.0f, // TexCoord 1
 
380
+               1.0f, 1.0f, 0.0f, // Position 2
 
381
+               1.0f, 1.0f, // TexCoord 2
 
382
+               1.0f, 0.0f, 0.0f, // Position 3
 
383
+               1.0f, 0.0f // TexCoord 3
 
384
+       };
 
385
+
 
386
+       GLushort indices[] = { 0, 1, 2, 0, 2, 3 };
 
387
+
 
388
+       // Set the viewport
 
389
+       // Clear the color buffer
 
390
+       glClear(GL_COLOR_BUFFER_BIT);
 
391
+       // Use the program object
 
392
+       glUseProgram(render_data.program_object);
 
393
+       // Enable attributes
 
394
+       glEnableVertexAttribArray(render_data.position_loc);
 
395
+       glEnableVertexAttribArray(render_data.tex_coord_loc);
 
396
+       // Load the vertex position
 
397
+       glVertexAttribPointer(render_data.position_loc,
 
398
+                       3,
 
399
+                       GL_FLOAT,
 
400
+                       GL_FALSE,
 
401
+                       5 * sizeof(GLfloat),
 
402
+                       vVertices);
 
403
+       // Load the texture coordinate
 
404
+       glVertexAttribPointer(render_data.tex_coord_loc,
 
405
+                       2,
 
406
+                       GL_FLOAT,
 
407
+                       GL_FALSE,
 
408
+                       5 * sizeof(GLfloat),
 
409
+                       vVertices+3);
 
410
+
 
411
+       glActiveTexture(GL_TEXTURE0);
 
412
+       // Set the sampler texture unit to 0
 
413
+       glUniform1i(render_data.sampler_loc, 0);
 
414
+       glUniform1i(render_data.matrix_loc, 0);
 
415
+       ALOGD("Updating the preview texture");
 
416
+       if (camera_control != NULL)
 
417
+               android_camera_update_preview_texture(camera_control);
 
418
+       glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_SHORT, indices);
 
419
+       glDisableVertexAttribArray(render_data.position_loc);
 
420
+       glDisableVertexAttribArray(render_data.tex_coord_loc);
 
421
+
 
422
+       eglSwapBuffers(disp, surface);
 
423
+}
 
424
+
 
425
+static void errorCB(void *context)
 
426
+{
 
427
+       ALOGE("Error while recording.");
 
428
+}
 
429
+
 
430
+static MediaRecorderWrapper *start_video_recording(CameraControl *camera_control)
 
431
+{
 
432
+       int ret = 0;
 
433
+       struct MediaRecorderWrapper *recorder = android_media_new_recorder();
 
434
+       android_recorder_set_error_cb(recorder, &errorCB, NULL);
 
435
+
 
436
+       ALOGD("Unlocking camera");
 
437
+       android_camera_unlock(camera_control);
 
438
+       if (recorder == NULL)
 
439
+               ALOGW("recorder is NULL: %d", __LINE__);
 
440
+
 
441
+       ret = android_recorder_setCamera(recorder, camera_control);
 
442
+       if (ret < 0) {
 
443
+               ALOGE("android_recorder_setCamera() failed");
 
444
+               return NULL;
 
445
+       }
 
446
+       ret = android_recorder_setAudioSource(recorder, ANDROID_AUDIO_SOURCE_CAMCORDER);
 
447
+       if (ret < 0) {
 
448
+               ALOGE("android_recorder_setAudioSource() failed");
 
449
+               return NULL;
 
450
+       }
 
451
+       ret = android_recorder_setVideoSource(recorder, ANDROID_VIDEO_SOURCE_CAMERA);
 
452
+       if (ret < 0) {
 
453
+               ALOGE("android_recorder_setVideoSource() failed");
 
454
+               return NULL;
 
455
+       }
 
456
+       ret = android_recorder_setOutputFormat(recorder, ANDROID_OUTPUT_FORMAT_MPEG_4);
 
457
+       if (ret < 0) {
 
458
+               ALOGE("android_recorder_setOutputFormat() failed");
 
459
+               return NULL;
 
460
+       }
 
461
+       ret = android_recorder_setAudioEncoder(recorder, ANDROID_AUDIO_ENCODER_AAC);
 
462
+       if (ret < 0) {
 
463
+               ALOGE("android_recorder_setAudioEncoder() failed");
 
464
+               return NULL;
 
465
+       }
 
466
+       ret = android_recorder_setVideoEncoder(recorder, ANDROID_VIDEO_ENCODER_H264);
 
467
+       if (ret < 0) {
 
468
+               ALOGE("android_recorder_setVideoEncoder() failed");
 
469
+               return NULL;
 
470
+       }
 
471
+       int fd = -1;
 
472
+       char *out_file = "/cache/test_recording.mp4";
 
473
+       fd = open(out_file, O_WRONLY | O_CREAT,
 
474
+                         S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
 
475
+       if (fd < 0) {
 
476
+               ALOGE("Couldn't open output video file for recording: %s", out_file);
 
477
+               return NULL;
 
478
+       }
 
479
+       ret = android_recorder_setOutputFile(recorder, fd);
 
480
+       if (ret < 0) {
 
481
+               ALOGE("android_recorder_setOutputFile() failed");
 
482
+               return NULL;
 
483
+       }
 
484
+       ret = android_recorder_setVideoSize(recorder, camera_width, camera_height);
 
485
+       if (ret < 0) {
 
486
+               ALOGE("android_recorder_setVideoSize() failed");
 
487
+               return NULL;
 
488
+       }
 
489
+       ret = android_recorder_setVideoFrameRate(recorder, 30);
 
490
+       if (ret < 0) {
 
491
+               ALOGE("android_recorder_setVideoFrameRate() failed");
 
492
+               return NULL;
 
493
+       }
 
494
+       android_recorder_setParameters(recorder, "video-param-encoding-bitrate=5505024"); // 7*1024*768
 
495
+       android_recorder_setParameters(recorder, "audio-param-encoding-bitrate=48000");
 
496
+       android_recorder_setParameters(recorder, "audio-param-number-of-channels=2");
 
497
+       android_recorder_setParameters(recorder, "audio-param-sampling-rate=96000");
 
498
+       android_recorder_setParameters(recorder, "video-param-rotation-angle-degrees=90");
 
499
+       ALOGD("Preparing video recording");
 
500
+       ret = android_recorder_prepare(recorder);
 
501
+       if (ret < 0) {
 
502
+               ALOGE("android_recorder_prepare() failed");
 
503
+               return NULL;
 
504
+       }
 
505
+       ALOGD("Starting video recording");
 
506
+       ret = android_recorder_start(recorder);
 
507
+       if (ret < 0) {
 
508
+               ALOGE("android_recorder_start() failed");
 
509
+               return NULL;
 
510
+       }
 
511
+
 
512
+       return recorder;
 
513
+}
 
514
+
 
515
+static void stop_video_recording(MediaRecorderWrapper *recorder)
 
516
+{
 
517
+       if (recording) {
 
518
+               ALOGD("Stopping video recording");
 
519
+               android_recorder_stop(recorder);
 
520
+               android_recorder_reset(recorder);
 
521
+               android_recorder_release(recorder);
 
522
+               ALOGD("Stopped video recording");
 
523
+       }
 
524
+}
 
525
+
 
526
+void on_new_input_event(Event* event, void* context)
 
527
+{
 
528
+       assert(context);
 
529
+
 
530
+       if (event->type == KEY_EVENT_TYPE && event->action == ISCL_KEY_EVENT_ACTION_UP) {
 
531
+               printf("We got a key event: %d \n", event->details.key.key_code);
 
532
+
 
533
+               CameraControl* cc = static_cast<CameraControl*>(context);
 
534
+
 
535
+               switch(event->details.key.key_code) {
 
536
+               case ISCL_KEYCODE_VOLUME_UP:
 
537
+                       printf("Starting video recording to /cache/test_recording.mp4\n");
 
538
+                       start_video_recording(cc);
 
539
+                       recording = true;
 
540
+                       break;
 
541
+               case ISCL_KEYCODE_VOLUME_DOWN:
 
542
+                       printf("Stopping video recording\n");
 
543
+                       stop_video_recording(recorder);
 
544
+                       recording = false;
 
545
+                       break;
 
546
+               case ISCL_KEYCODE_POWER:
 
547
+                       printf("\tTaking a photo now.\n");
 
548
+                       android_camera_take_snapshot(cc);
 
549
+                       break;
 
550
+               case ISCL_KEYCODE_HEADSETHOOK:
 
551
+                       printf("\tSwitching effect.\n");
 
552
+                       android_camera_set_effect_mode(cc, next_effect());
 
553
+               }
 
554
+       } else if (event->type == MOTION_EVENT_TYPE &&
 
555
+                       event->details.motion.pointer_count == 1) {
 
556
+               if ((event->action & ISCL_MOTION_EVENT_ACTION_MASK) == ISCL_MOTION_EVENT_ACTION_UP) {
 
557
+                       printf("\tMotion event(Action up): (%f, %f) \n",
 
558
+                                       event->details.motion.pointer_coordinates[0].x,
 
559
+                                       event->details.motion.pointer_coordinates[0].y);
 
560
+               }
 
561
+
 
562
+               if ((event->action & ISCL_MOTION_EVENT_ACTION_MASK) == ISCL_MOTION_EVENT_ACTION_DOWN) {
 
563
+                       printf("\tMotion event(Action down): (%f, %f) \n",
 
564
+                                       event->details.motion.pointer_coordinates[0].x,
 
565
+                                       event->details.motion.pointer_coordinates[0].y);
 
566
+               }
 
567
+       }
 
568
+}
 
569
+
 
570
+struct ClientWithSurface
 
571
+{
 
572
+       SfClient* client;
 
573
+       SfSurface* surface;
 
574
+};
 
575
+
 
576
+ClientWithSurface client_with_surface(bool setup_surface_with_egl)
 
577
+{
 
578
+       ClientWithSurface cs = ClientWithSurface();
 
579
+
 
580
+       cs.client = sf_client_create();
 
581
+
 
582
+       if (!cs.client) {
 
583
+               printf("Problem creating client ... aborting now.");
 
584
+               return cs;
 
585
+       }
 
586
+
 
587
+       static const size_t primary_display = 0;
 
588
+
 
589
+       SfSurfaceCreationParameters params = {
 
590
+               0,
 
591
+               0,
 
592
+               (int) sf_get_display_width(primary_display),
 
593
+               (int) sf_get_display_height(primary_display),
 
594
+               -1, //PIXEL_FORMAT_RGBA_8888,
 
595
+               15000,
 
596
+               0.5f,
 
597
+               setup_surface_with_egl, // Do not associate surface with egl, will be done by camera HAL
 
598
+               "CameraCompatLayerTestSurface"
 
599
+       };
 
600
+
 
601
+       cs.surface = sf_surface_create(cs.client, &params);
 
602
+
 
603
+       if (!cs.surface) {
 
604
+               printf("Problem creating surface ... aborting now.");
 
605
+               return cs;
 
606
+       }
 
607
+
 
608
+       sf_surface_make_current(cs.surface);
 
609
+
 
610
+       return cs;
 
611
+}
 
612
+
 
613
+#define PRINT_GLERROR() printf("GL error@%d: %x\n", __LINE__, glGetError());
 
614
+
 
615
 int main(int argc, char** argv)
 
616
 {
 
617
        CameraControlListener listener;
 
618
@@ -366,80 +532,103 @@ int main(int argc, char** argv)
 
619
        listener.on_data_raw_image_cb = raw_data_cb;
 
620
        listener.on_data_compressed_image_cb = jpeg_data_cb;
 
621
        listener.on_preview_texture_needs_update_cb = preview_texture_needs_update_cb;
 
622
-       CameraControl* cc = android_camera_connect_to(FRONT_FACING_CAMERA_TYPE,
 
623
+       camera_control = android_camera_connect_to(BACK_FACING_CAMERA_TYPE,
 
624
                        &listener);
 
625
 
 
626
-       if (cc == NULL) {
 
627
+       if (camera_control == NULL) {
 
628
                printf("Problem connecting to camera");
 
629
                return 1;
 
630
        }
 
631
-
 
632
-       listener.context = cc;
 
633
+       listener.context = camera_control;
 
634
 
 
635
        AndroidEventListener event_listener;
 
636
        event_listener.on_new_event = on_new_input_event;
 
637
-       event_listener.context = cc;
 
638
+       event_listener.context = camera_control;
 
639
 
 
640
-       InputStackConfiguration input_configuration = { true, 25000 };
 
641
+       InputStackConfiguration input_configuration = {
 
642
+               enable_touch_point_visualization : true,
 
643
+               default_layer_for_touch_point_visualization : 10000,
 
644
+               input_area_width : 1024,
 
645
+               input_area_height : 1024
 
646
+       };
 
647
 
 
648
        android_input_stack_initialize(&event_listener, &input_configuration);
 
649
        android_input_stack_start();
 
650
 
 
651
-       android_camera_dump_parameters(cc);
 
652
-       android_camera_enumerate_supported_picture_sizes(cc, size_cb, NULL);
 
653
-       android_camera_enumerate_supported_preview_sizes(cc, size_cb, NULL);
 
654
+       android_camera_enumerate_supported_picture_sizes(camera_control, size_cb, NULL);
 
655
+       if (camera_width == 0 && camera_height == 0) {
 
656
+               camera_width = 320;
 
657
+               camera_height = 240;
 
658
+       }
 
659
+       android_camera_set_picture_size(camera_control, camera_width, camera_height);
 
660
+
 
661
+       AutoFocusMode af_mode;
 
662
+       android_camera_get_auto_focus_mode(camera_control, &af_mode);
 
663
+       printf("Current af mode: %d \n", af_mode);
 
664
+
 
665
+       int zoom;
 
666
+       android_camera_set_zoom(camera_control, 0);
 
667
+       android_camera_get_max_zoom(camera_control, &zoom);
 
668
+       printf("Max zoom: %d \n", zoom);
 
669
+
 
670
+       android_camera_enumerate_supported_video_sizes(camera_control, size_cb, NULL);
 
671
+       android_camera_enumerate_supported_preview_sizes(camera_control, size_cb, NULL);
 
672
+       android_camera_set_preview_size(camera_control, camera_width, camera_height);
 
673
 
 
674
        int min_fps, max_fps, current_fps;
 
675
-       android_camera_get_preview_fps_range(cc, &min_fps, &max_fps);
 
676
+       android_camera_get_preview_fps_range(camera_control, &min_fps, &max_fps);
 
677
        printf("Preview fps range: [%d,%d]\n", min_fps, max_fps);
 
678
-       android_camera_get_preview_fps(cc, &current_fps);
 
679
+       android_camera_get_preview_fps(camera_control, &current_fps);
 
680
        printf("Current preview fps range: %d\n", current_fps);
 
681
 
 
682
-       android_camera_set_preview_size(cc, 960, 720);
 
683
+#if 0
 
684
+       android_camera_dump_parameters(camera_control);
 
685
+
 
686
+       android_camera_set_display_orientation(camera_control, 90);
 
687
 
 
688
        int width, height;
 
689
-       android_camera_get_preview_size(cc, &width, &height);
 
690
+       android_camera_get_preview_size(camera_control, &width, &height);
 
691
        printf("Current preview size: [%d,%d]\n", width, height);
 
692
-       android_camera_get_picture_size(cc, &width, &height);
 
693
+       android_camera_get_picture_size(camera_control, &width, &height);
 
694
        printf("Current picture size: [%d,%d]\n", width, height);
 
695
-       int zoom;
 
696
-       android_camera_get_current_zoom(cc, &zoom);
 
697
+       android_camera_get_current_zoom(camera_control, &zoom);
 
698
        printf("Current zoom: %d \n", zoom);
 
699
-       android_camera_get_max_zoom(cc, &zoom);
 
700
-       printf("Max zoom: %d \n", zoom);
 
701
 
 
702
        EffectMode effect_mode;
 
703
        FlashMode flash_mode;
 
704
        WhiteBalanceMode wb_mode;
 
705
-       SceneMode scene_mode;
 
706
-       AutoFocusMode af_mode;
 
707
+       //SceneMode scene_mode;
 
708
        CameraPixelFormat pixel_format;
 
709
-       android_camera_get_effect_mode(cc, &effect_mode);
 
710
-       android_camera_get_flash_mode(cc, &flash_mode);
 
711
-       android_camera_get_white_balance_mode(cc, &wb_mode);
 
712
-       android_camera_get_scene_mode(cc, &scene_mode);
 
713
-       android_camera_get_auto_focus_mode(cc, &af_mode);
 
714
-       android_camera_get_preview_format(cc, &pixel_format);
 
715
+       android_camera_get_effect_mode(camera_control, &effect_mode);
 
716
        printf("Current effect mode: %d \n", effect_mode);
 
717
+       android_camera_get_flash_mode(camera_control, &flash_mode);
 
718
        printf("Current flash mode: %d \n", flash_mode);
 
719
-       printf("Current wb mode: %d \n", wb_mode);
 
720
+       android_camera_get_white_balance_mode(camera_control, &wb_mode);
 
721
+       ALOGD("Current wb mode: %d \n", wb_mode);
 
722
+#if 0
 
723
+       // Disabled, causes the test app to crash
 
724
+       android_camera_get_scene_mode(camera_control, &scene_mode);
 
725
        printf("Current scene mode: %d \n", scene_mode);
 
726
-       printf("Current af mode: %d \n", af_mode);
 
727
+#endif
 
728
+       android_camera_get_preview_format(camera_control, &pixel_format);
 
729
        printf("Current preview pixel format: %d \n", pixel_format);
 
730
-       //android_camera_set_focus_region(cc, -200, -200, 200, 200, 300);
 
731
+       //android_camera_set_focus_region(camera_control, -200, -200, 200, 200, 300);
 
732
+#endif
 
733
 
 
734
+       printf("Creating client with surface");
 
735
        ClientWithSurface cs = client_with_surface(true /* Associate surface with egl. */);
 
736
 
 
737
        if (!cs.surface) {
 
738
                printf("Problem acquiring surface for preview");
 
739
                return 1;
 
740
        }
 
741
+       printf("Finished creating client with surface\n");
 
742
 
 
743
-       EGLDisplay disp = sf_client_get_egl_display(cs.client);
 
744
-       EGLSurface surface = sf_surface_get_egl_surface(cs.surface);
 
745
+       disp = sf_client_get_egl_display(cs.client);
 
746
+       surface = sf_surface_get_egl_surface(cs.surface);
 
747
 
 
748
-       RenderData render_data;
 
749
        GLuint preview_texture_id;
 
750
+       printf("Getting a texture id\n");
 
751
        glGenTextures(1, &preview_texture_id);
 
752
        glClearColor(1.0, 0., 0.5, 1.);
 
753
        glTexParameteri(GL_TEXTURE_EXTERNAL_OES, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
 
754
@@ -448,68 +637,26 @@ int main(int argc, char** argv)
 
755
                        GL_TEXTURE_EXTERNAL_OES, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
 
756
        glTexParameteri(
 
757
                        GL_TEXTURE_EXTERNAL_OES, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
 
758
-       android_camera_set_preview_texture(cc, preview_texture_id);
 
759
-       android_camera_set_effect_mode(cc, EFFECT_MODE_SEPIA);
 
760
-       android_camera_set_flash_mode(cc, FLASH_MODE_AUTO);
 
761
-       android_camera_set_auto_focus_mode(cc, AUTO_FOCUS_MODE_CONTINUOUS_PICTURE);
 
762
-       android_camera_start_preview(cc);
 
763
+       printf("About to set preview texture\n");
 
764
+       android_camera_set_preview_texture(camera_control, preview_texture_id);
 
765
+#if 0
 
766
+       android_camera_set_effect_mode(camera_control, EFFECT_MODE_SEPIA);
 
767
+       android_camera_set_flash_mode(camera_control, FLASH_MODE_AUTO);
 
768
+       android_camera_set_auto_focus_mode(camera_control, AUTO_FOCUS_MODE_CONTINUOUS_PICTURE);
 
769
+#endif
 
770
+       android_camera_start_preview(camera_control);
 
771
 
 
772
        GLfloat transformation_matrix[16];
 
773
-       android_camera_get_preview_texture_transformation(cc, transformation_matrix);
 
774
+       android_camera_get_preview_texture_transformation(camera_control, transformation_matrix);
 
775
        glUniformMatrix4fv(render_data.matrix_loc, 1, GL_FALSE, transformation_matrix);
 
776
 
 
777
        printf("Started camera preview.\n");
 
778
 
 
779
-       while (true) {
 
780
-               /*if (new_camera_frame_available)
 
781
-                 {
 
782
-                 printf("Updating texture");
 
783
-                 new_camera_frame_available = false;
 
784
-                 }*/
 
785
-               static GLfloat vVertices[] = { 0.0f, 0.0f, 0.0f, // Position 0
 
786
-                       0.0f, 0.0f, // TexCoord 0
 
787
-                       0.0f, 1.0f, 0.0f, // Position 1
 
788
-                       0.0f, 1.0f, // TexCoord 1
 
789
-                       1.0f, 1.0f, 0.0f, // Position 2
 
790
-                       1.0f, 1.0f, // TexCoord 2
 
791
-                       1.0f, 0.0f, 0.0f, // Position 3
 
792
-                       1.0f, 0.0f // TexCoord 3
 
793
-               };
 
794
-
 
795
-               GLushort indices[] = { 0, 1, 2, 0, 2, 3 };
 
796
-
 
797
-               // Set the viewport
 
798
-               // Clear the color buffer
 
799
-               glClear(GL_COLOR_BUFFER_BIT);
 
800
-               // Use the program object
 
801
-               glUseProgram(render_data.program_object);
 
802
-               // Enable attributes
 
803
-               glEnableVertexAttribArray(render_data.position_loc);
 
804
-               glEnableVertexAttribArray(render_data.tex_coord_loc);
 
805
-               // Load the vertex position
 
806
-               glVertexAttribPointer(render_data.position_loc,
 
807
-                               3,
 
808
-                               GL_FLOAT,
 
809
-                               GL_FALSE,
 
810
-                               5 * sizeof(GLfloat),
 
811
-                               vVertices);
 
812
-               // Load the texture coordinate
 
813
-               glVertexAttribPointer(render_data.tex_coord_loc,
 
814
-                               2,
 
815
-                               GL_FLOAT,
 
816
-                               GL_FALSE,
 
817
-                               5 * sizeof(GLfloat),
 
818
-                               vVertices+3);
 
819
-
 
820
-               glActiveTexture(GL_TEXTURE0);
 
821
-               // Set the sampler texture unit to 0
 
822
-               glUniform1i(render_data.sampler_loc, 0);
 
823
-               glUniform1i(render_data.matrix_loc, 0);
 
824
-               android_camera_update_preview_texture(cc);
 
825
-               glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_SHORT, indices);
 
826
-               glDisableVertexAttribArray(render_data.position_loc);
 
827
-               glDisableVertexAttribArray(render_data.tex_coord_loc);
 
828
-
 
829
-               eglSwapBuffers(disp, surface);
 
830
+       while (1) {
 
831
+               usleep(50);
 
832
        }
 
833
+
 
834
+       stop_video_recording(recorder);
 
835
+       android_camera_stop_preview(camera_control);
 
836
+       android_camera_disconnect(camera_control);
 
837
 }
140
838
--- libhybris-0.1.0+git20131207+e452e83.orig/compat/input/Android.mk
141
839
+++ libhybris-0.1.0+git20131207+e452e83/compat/input/Android.mk
142
840
@@ -18,6 +18,11 @@ LOCAL_SHARED_LIBRARIES := \
153
851
        external/skia/include/core \
154
852
--- /dev/null
155
853
+++ libhybris-0.1.0+git20131207+e452e83/compat/media/Android.mk
156
 
@@ -0,0 +1,110 @@
 
854
@@ -0,0 +1,145 @@
157
855
+LOCAL_PATH:= $(call my-dir)
158
856
+include $(CLEAR_VARS)
 
857
+
 
858
+LOCAL_SRC_FILES := \
 
859
+       camera_service.cpp
 
860
+
 
861
+LOCAL_SHARED_LIBRARIES := \
 
862
+       libcameraservice \
 
863
+       libmedialogservice \
 
864
+       libcutils \
 
865
+       libmedia_compat_layer \
 
866
+       libmediaplayerservice \
 
867
+       libutils \
 
868
+       liblog \
 
869
+       libbinder
 
870
+
 
871
+LOCAL_C_INCLUDES := \
 
872
+    frameworks/av/media/libmediaplayerservice \
 
873
+    frameworks/av/services/medialog \
 
874
+    frameworks/av/services/camera/libcameraservice
 
875
+
 
876
+LOCAL_MODULE := camera_service
 
877
+
 
878
+include $(BUILD_EXECUTABLE)
 
879
+
 
880
+# -------------------------------------------------
 
881
+
 
882
+include $(CLEAR_VARS)
159
883
+include $(LOCAL_PATH)/../Android.common.mk
160
884
+
161
885
+HYBRIS_PATH := $(LOCAL_PATH)/../../hybris
169
893
+       media_format_layer.cpp \
170
894
+       surface_texture_client_hybris.cpp \
171
895
+       decoding_service.cpp \
172
 
+       recorder_compatibility_layer.cpp
 
896
+       media_recorder_layer.cpp \
 
897
+       media_recorder.cpp \
 
898
+       media_recorder_client.cpp \
 
899
+       media_recorder_factory.cpp
173
900
+
174
901
+LOCAL_MODULE:= libmedia_compat_layer
175
902
+LOCAL_MODULE_TAGS := optional
186
913
+       libstagefright_foundation \
187
914
+       libEGL \
188
915
+       libGLESv2 \
189
 
+       libmedia
 
916
+       libmedia \
 
917
+       libcameraservice \
 
918
+       libmediaplayerservice
190
919
+
191
920
+LOCAL_C_INCLUDES := \
192
921
+       $(HYBRIS_PATH)/include \
193
922
+       frameworks/base/media/libstagefright/include \
194
923
+       frameworks/base/include/media/stagefright \
195
 
+       frameworks/base/include/media
 
924
+       frameworks/base/include/media \
 
925
+       frameworks/av/media \
 
926
+       frameworks/av/services/camera/libcameraservice
196
927
+
197
928
+include $(BUILD_SHARED_LIBRARY)
198
929
+
 
930
+# -------------------------------------------------
 
931
+
199
932
+include $(CLEAR_VARS)
200
933
+include $(LOCAL_PATH)/../Android.common.mk
201
934
+
1168
1901
+
1169
1902
+}  // namespace android
1170
1903
--- /dev/null
 
1904
+++ libhybris-0.1.0+git20131207+e452e83/compat/media/camera_service.cpp
 
1905
@@ -0,0 +1,48 @@
 
1906
+/*
 
1907
+ * Copyright (C) 2014 Canonical Ltd
 
1908
+ *
 
1909
+ * Licensed under the Apache License, Version 2.0 (the "License");
 
1910
+ * you may not use this file except in compliance with the License.
 
1911
+ * You may obtain a copy of the License at
 
1912
+ *
 
1913
+ *      http://www.apache.org/licenses/LICENSE-2.0
 
1914
+ *
 
1915
+ * Unless required by applicable law or agreed to in writing, software
 
1916
+ * distributed under the License is distributed on an "AS IS" BASIS,
 
1917
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 
1918
+ * See the License for the specific language governing permissions and
 
1919
+ * limitations under the License.
 
1920
+ *
 
1921
+ * Authored by: Jim Hodapp <jim.hodapp@canonical.com>
 
1922
+ */
 
1923
+
 
1924
+#define LOG_NDEBUG 0
 
1925
+#undef LOG_TAG
 
1926
+#define LOG_TAG "CameraServiceCompatLayer"
 
1927
+
 
1928
+#include "media_recorder_factory.h"
 
1929
+#include "media_recorder.h"
 
1930
+#include <CameraService.h>
 
1931
+
 
1932
+#include <signal.h>
 
1933
+
 
1934
+#define REPORT_FUNCTION() ALOGV("%s \n", __PRETTY_FUNCTION__)
 
1935
+
 
1936
+using namespace android;
 
1937
+
 
1938
+/*!
 
1939
+ * \brief main() instantiates the MediaRecorderFactory Binder server and the CameraService
 
1940
+ */
 
1941
+int main(int argc, char** argv)
 
1942
+{
 
1943
+    signal(SIGPIPE, SIG_IGN);
 
1944
+
 
1945
+    ALOGV("Starting RecordingService (MediaRecorderFactory & CameraService)");
 
1946
+
 
1947
+    // Instantiate the in-process MediaRecorderFactory which is responsible
 
1948
+    // for creating a new IMediaRecorder (MediaRecorder) instance over Binder
 
1949
+    MediaRecorderFactory::instantiate();
 
1950
+    CameraService::instantiate();
 
1951
+    ProcessState::self()->startThreadPool();
 
1952
+    IPCThreadState::self()->joinThreadPool();
 
1953
+}
 
1954
--- /dev/null
1171
1955
+++ libhybris-0.1.0+git20131207+e452e83/compat/media/codec.cpp
1172
1956
@@ -0,0 +1,433 @@
1173
1957
+/*
4736
5520
+
4737
5521
+#endif // MEDIA_FORMAT_LAYER_PRIV_H_
4738
5522
--- /dev/null
4739
 
+++ libhybris-0.1.0+git20131207+e452e83/compat/media/recorder_compatibility_layer.cpp
4740
 
@@ -0,0 +1,457 @@
4741
 
+/*
4742
 
+ * Copyright (C) 2013 Canonical Ltd
 
5523
+++ libhybris-0.1.0+git20131207+e452e83/compat/media/media_recorder.cpp
 
5524
@@ -0,0 +1,722 @@
 
5525
+/*
 
5526
+ ** Copyright (c) 2008 The Android Open Source Project
 
5527
+ ** Copyright (C) 2014 Canonical Ltd
 
5528
+ **
 
5529
+ ** Adapted from the Android equivalent code for use in Ubuntu.
 
5530
+ **
 
5531
+ ** Licensed under the Apache License, Version 2.0 (the "License");
 
5532
+ ** you may not use this file except in compliance with the License.
 
5533
+ ** You may obtain a copy of the License at
 
5534
+ **
 
5535
+ **     http://www.apache.org/licenses/LICENSE-2.0
 
5536
+ **
 
5537
+ ** Unless required by applicable law or agreed to in writing, software
 
5538
+ ** distributed under the License is distributed on an "AS IS" BASIS,
 
5539
+ ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 
5540
+ ** See the License for the specific language governing permissions and
 
5541
+ ** limitations under the License.
 
5542
+ */
 
5543
+
 
5544
+//#define LOG_NDEBUG 0
 
5545
+#define LOG_TAG "MediaRecorder"
 
5546
+
 
5547
+#include "media_recorder.h"
 
5548
+#include "media_recorder_factory.h"
 
5549
+
 
5550
+#include <utils/Log.h>
 
5551
+#include <binder/IServiceManager.h>
 
5552
+#include <utils/String8.h>
 
5553
+#include <media/IMediaPlayerService.h>
 
5554
+#include <media/IMediaRecorder.h>
 
5555
+#include <media/mediaplayer.h>  // for MEDIA_ERROR_SERVER_DIED
 
5556
+#include <gui/IGraphicBufferProducer.h>
 
5557
+
 
5558
+namespace android {
 
5559
+
 
5560
+status_t MediaRecorder::setCamera(const sp<ICamera>& camera, const sp<ICameraRecordingProxy>& proxy)
 
5561
+{
 
5562
+    ALOGV("setCamera(%p,%p)", camera.get(), proxy.get());
 
5563
+    if (mMediaRecorder == NULL) {
 
5564
+        ALOGE("media recorder is not initialized yet");
 
5565
+        return INVALID_OPERATION;
 
5566
+    }
 
5567
+    if (!(mCurrentState & MEDIA_RECORDER_IDLE)) {
 
5568
+        ALOGE("setCamera called in an invalid state(%d)", mCurrentState);
 
5569
+        return INVALID_OPERATION;
 
5570
+    }
 
5571
+
 
5572
+    status_t ret = mMediaRecorder->setCamera(camera, proxy);
 
5573
+    if (OK != ret) {
 
5574
+        ALOGV("setCamera failed: %d", ret);
 
5575
+        mCurrentState = MEDIA_RECORDER_ERROR;
 
5576
+        return ret;
 
5577
+    }
 
5578
+    return ret;
 
5579
+}
 
5580
+
 
5581
+status_t MediaRecorder::setPreviewSurface(const sp<IGraphicBufferProducer>& surface)
 
5582
+{
 
5583
+    ALOGV("setPreviewSurface(%p)", surface.get());
 
5584
+    if (mMediaRecorder == NULL) {
 
5585
+        ALOGE("media recorder is not initialized yet");
 
5586
+        return INVALID_OPERATION;
 
5587
+    }
 
5588
+    if (!(mCurrentState & MEDIA_RECORDER_DATASOURCE_CONFIGURED)) {
 
5589
+        ALOGE("setPreviewSurface called in an invalid state(%d)", mCurrentState);
 
5590
+        return INVALID_OPERATION;
 
5591
+    }
 
5592
+    if (!mIsVideoSourceSet) {
 
5593
+        ALOGE("try to set preview surface without setting the video source first");
 
5594
+        return INVALID_OPERATION;
 
5595
+    }
 
5596
+
 
5597
+    status_t ret = mMediaRecorder->setPreviewSurface(surface);
 
5598
+    if (OK != ret) {
 
5599
+        ALOGV("setPreviewSurface failed: %d", ret);
 
5600
+        mCurrentState = MEDIA_RECORDER_ERROR;
 
5601
+        return ret;
 
5602
+    }
 
5603
+    return ret;
 
5604
+}
 
5605
+
 
5606
+status_t MediaRecorder::init()
 
5607
+{
 
5608
+    ALOGV("init");
 
5609
+    if (mMediaRecorder == NULL) {
 
5610
+        ALOGE("media recorder is not initialized yet");
 
5611
+        return INVALID_OPERATION;
 
5612
+    }
 
5613
+    if (!(mCurrentState & MEDIA_RECORDER_IDLE)) {
 
5614
+        ALOGE("init called in an invalid state(%d)", mCurrentState);
 
5615
+        return INVALID_OPERATION;
 
5616
+    }
 
5617
+
 
5618
+    status_t ret = mMediaRecorder->init();
 
5619
+    if (OK != ret) {
 
5620
+        ALOGV("init failed: %d", ret);
 
5621
+        mCurrentState = MEDIA_RECORDER_ERROR;
 
5622
+        return ret;
 
5623
+    }
 
5624
+
 
5625
+    ret = mMediaRecorder->setListener(this);
 
5626
+    if (OK != ret) {
 
5627
+        ALOGV("setListener failed: %d", ret);
 
5628
+        mCurrentState = MEDIA_RECORDER_ERROR;
 
5629
+        return ret;
 
5630
+    }
 
5631
+
 
5632
+    mCurrentState = MEDIA_RECORDER_INITIALIZED;
 
5633
+    return ret;
 
5634
+}
 
5635
+
 
5636
+status_t MediaRecorder::setVideoSource(int vs)
 
5637
+{
 
5638
+    ALOGV("setVideoSource(%d)", vs);
 
5639
+    if (mMediaRecorder == NULL) {
 
5640
+        ALOGE("media recorder is not initialized yet");
 
5641
+        return INVALID_OPERATION;
 
5642
+    }
 
5643
+    if (mIsVideoSourceSet) {
 
5644
+        ALOGE("video source has already been set");
 
5645
+        return INVALID_OPERATION;
 
5646
+    }
 
5647
+    if (mCurrentState & MEDIA_RECORDER_IDLE) {
 
5648
+        ALOGV("Call init() since the media recorder is not initialized yet");
 
5649
+        status_t ret = init();
 
5650
+        if (OK != ret) {
 
5651
+            return ret;
 
5652
+        }
 
5653
+    }
 
5654
+    if (!(mCurrentState & MEDIA_RECORDER_INITIALIZED)) {
 
5655
+        ALOGE("setVideoSource called in an invalid state(%d)", mCurrentState);
 
5656
+        return INVALID_OPERATION;
 
5657
+    }
 
5658
+
 
5659
+    // following call is made over the Binder Interface
 
5660
+    status_t ret = mMediaRecorder->setVideoSource(vs);
 
5661
+
 
5662
+    if (OK != ret) {
 
5663
+        ALOGV("setVideoSource failed: %d", ret);
 
5664
+        mCurrentState = MEDIA_RECORDER_ERROR;
 
5665
+        return ret;
 
5666
+    }
 
5667
+    mIsVideoSourceSet = true;
 
5668
+    return ret;
 
5669
+}
 
5670
+
 
5671
+status_t MediaRecorder::setAudioSource(int as)
 
5672
+{
 
5673
+    ALOGV("setAudioSource(%d)", as);
 
5674
+    if (mMediaRecorder == NULL) {
 
5675
+        ALOGE("media recorder is not initialized yet");
 
5676
+        return INVALID_OPERATION;
 
5677
+    }
 
5678
+    if (mCurrentState & MEDIA_RECORDER_IDLE) {
 
5679
+        ALOGV("Call init() since the media recorder is not initialized yet");
 
5680
+        status_t ret = init();
 
5681
+        if (OK != ret) {
 
5682
+            return ret;
 
5683
+        }
 
5684
+    }
 
5685
+    if (mIsAudioSourceSet) {
 
5686
+        ALOGE("audio source has already been set");
 
5687
+        return INVALID_OPERATION;
 
5688
+    }
 
5689
+    if (!(mCurrentState & MEDIA_RECORDER_INITIALIZED)) {
 
5690
+        ALOGE("setAudioSource called in an invalid state(%d)", mCurrentState);
 
5691
+        return INVALID_OPERATION;
 
5692
+    }
 
5693
+
 
5694
+    status_t ret = mMediaRecorder->setAudioSource(as);
 
5695
+    if (OK != ret) {
 
5696
+        ALOGV("setAudioSource failed: %d", ret);
 
5697
+        mCurrentState = MEDIA_RECORDER_ERROR;
 
5698
+        return ret;
 
5699
+    }
 
5700
+    mIsAudioSourceSet = true;
 
5701
+    return ret;
 
5702
+}
 
5703
+
 
5704
+status_t MediaRecorder::setOutputFormat(int of)
 
5705
+{
 
5706
+    ALOGV("setOutputFormat(%d)", of);
 
5707
+    if (mMediaRecorder == NULL) {
 
5708
+        ALOGE("media recorder is not initialized yet");
 
5709
+        return INVALID_OPERATION;
 
5710
+    }
 
5711
+    if (!(mCurrentState & MEDIA_RECORDER_INITIALIZED)) {
 
5712
+        ALOGE("setOutputFormat called in an invalid state: %d", mCurrentState);
 
5713
+        return INVALID_OPERATION;
 
5714
+    }
 
5715
+    if (mIsVideoSourceSet && of >= OUTPUT_FORMAT_AUDIO_ONLY_START && of != OUTPUT_FORMAT_RTP_AVP && of != OUTPUT_FORMAT_MPEG2TS) { //first non-video output format
 
5716
+        ALOGE("output format (%d) is meant for audio recording only and incompatible with video recording", of);
 
5717
+        return INVALID_OPERATION;
 
5718
+    }
 
5719
+
 
5720
+    status_t ret = mMediaRecorder->setOutputFormat(of);
 
5721
+    if (OK != ret) {
 
5722
+        ALOGE("setOutputFormat failed: %d", ret);
 
5723
+        mCurrentState = MEDIA_RECORDER_ERROR;
 
5724
+        return ret;
 
5725
+    }
 
5726
+    mCurrentState = MEDIA_RECORDER_DATASOURCE_CONFIGURED;
 
5727
+    return ret;
 
5728
+}
 
5729
+
 
5730
+status_t MediaRecorder::setVideoEncoder(int ve)
 
5731
+{
 
5732
+    ALOGV("setVideoEncoder(%d)", ve);
 
5733
+    if (mMediaRecorder == NULL) {
 
5734
+        ALOGE("media recorder is not initialized yet");
 
5735
+        return INVALID_OPERATION;
 
5736
+    }
 
5737
+    if (!mIsVideoSourceSet) {
 
5738
+        ALOGE("try to set the video encoder without setting the video source first");
 
5739
+        return INVALID_OPERATION;
 
5740
+    }
 
5741
+    if (mIsVideoEncoderSet) {
 
5742
+        ALOGE("video encoder has already been set");
 
5743
+        return INVALID_OPERATION;
 
5744
+    }
 
5745
+    if (!(mCurrentState & MEDIA_RECORDER_DATASOURCE_CONFIGURED)) {
 
5746
+        ALOGE("setVideoEncoder called in an invalid state(%d)", mCurrentState);
 
5747
+        return INVALID_OPERATION;
 
5748
+    }
 
5749
+
 
5750
+    status_t ret = mMediaRecorder->setVideoEncoder(ve);
 
5751
+    if (OK != ret) {
 
5752
+        ALOGV("setVideoEncoder failed: %d", ret);
 
5753
+        mCurrentState = MEDIA_RECORDER_ERROR;
 
5754
+        return ret;
 
5755
+    }
 
5756
+    mIsVideoEncoderSet = true;
 
5757
+    return ret;
 
5758
+}
 
5759
+
 
5760
+status_t MediaRecorder::setAudioEncoder(int ae)
 
5761
+{
 
5762
+    ALOGV("setAudioEncoder(%d)", ae);
 
5763
+    if (mMediaRecorder == NULL) {
 
5764
+        ALOGE("media recorder is not initialized yet");
 
5765
+        return INVALID_OPERATION;
 
5766
+    }
 
5767
+    if (!mIsAudioSourceSet) {
 
5768
+        ALOGE("try to set the audio encoder without setting the audio source first");
 
5769
+        return INVALID_OPERATION;
 
5770
+    }
 
5771
+    if (mIsAudioEncoderSet) {
 
5772
+        ALOGE("audio encoder has already been set");
 
5773
+        return INVALID_OPERATION;
 
5774
+    }
 
5775
+    if (!(mCurrentState & MEDIA_RECORDER_DATASOURCE_CONFIGURED)) {
 
5776
+        ALOGE("setAudioEncoder called in an invalid state(%d)", mCurrentState);
 
5777
+        return INVALID_OPERATION;
 
5778
+    }
 
5779
+
 
5780
+    status_t ret = mMediaRecorder->setAudioEncoder(ae);
 
5781
+    if (OK != ret) {
 
5782
+        ALOGV("setAudioEncoder failed: %d", ret);
 
5783
+        mCurrentState = MEDIA_RECORDER_ERROR;
 
5784
+        return ret;
 
5785
+    }
 
5786
+    mIsAudioEncoderSet = true;
 
5787
+    return ret;
 
5788
+}
 
5789
+
 
5790
+status_t MediaRecorder::setOutputFile(const char* path)
 
5791
+{
 
5792
+    ALOGV("setOutputFile(%s)", path);
 
5793
+    if (mMediaRecorder == NULL) {
 
5794
+        ALOGE("media recorder is not initialized yet");
 
5795
+        return INVALID_OPERATION;
 
5796
+    }
 
5797
+    if (mIsOutputFileSet) {
 
5798
+        ALOGE("output file has already been set");
 
5799
+        return INVALID_OPERATION;
 
5800
+    }
 
5801
+    if (!(mCurrentState & MEDIA_RECORDER_DATASOURCE_CONFIGURED)) {
 
5802
+        ALOGE("setOutputFile called in an invalid state(%d)", mCurrentState);
 
5803
+        return INVALID_OPERATION;
 
5804
+    }
 
5805
+
 
5806
+    status_t ret = mMediaRecorder->setOutputFile(path);
 
5807
+    if (OK != ret) {
 
5808
+        ALOGV("setOutputFile failed: %d", ret);
 
5809
+        mCurrentState = MEDIA_RECORDER_ERROR;
 
5810
+        return ret;
 
5811
+    }
 
5812
+    mIsOutputFileSet = true;
 
5813
+    return ret;
 
5814
+}
 
5815
+
 
5816
+status_t MediaRecorder::setOutputFile(int fd, int64_t offset, int64_t length)
 
5817
+{
 
5818
+    ALOGV("setOutputFile(%d, %lld, %lld)", fd, offset, length);
 
5819
+    if (mMediaRecorder == NULL) {
 
5820
+        ALOGE("media recorder is not initialized yet");
 
5821
+        return INVALID_OPERATION;
 
5822
+    }
 
5823
+    if (mIsOutputFileSet) {
 
5824
+        ALOGE("output file has already been set");
 
5825
+        return INVALID_OPERATION;
 
5826
+    }
 
5827
+    if (!(mCurrentState & MEDIA_RECORDER_DATASOURCE_CONFIGURED)) {
 
5828
+        ALOGE("setOutputFile called in an invalid state(%d)", mCurrentState);
 
5829
+        return INVALID_OPERATION;
 
5830
+    }
 
5831
+
 
5832
+    // It appears that if an invalid file descriptor is passed through
 
5833
+    // binder calls, the server-side of the inter-process function call
 
5834
+    // is skipped. As a result, the check at the server-side to catch
 
5835
+    // the invalid file descritpor never gets invoked. This is to workaround
 
5836
+    // this issue by checking the file descriptor first before passing
 
5837
+    // it through binder call.
 
5838
+    if (fd < 0) {
 
5839
+        ALOGE("Invalid file descriptor: %d", fd);
 
5840
+        return BAD_VALUE;
 
5841
+    }
 
5842
+
 
5843
+    status_t ret = mMediaRecorder->setOutputFile(fd, offset, length);
 
5844
+    if (OK != ret) {
 
5845
+        ALOGV("setOutputFile failed: %d", ret);
 
5846
+        mCurrentState = MEDIA_RECORDER_ERROR;
 
5847
+        return ret;
 
5848
+    }
 
5849
+    mIsOutputFileSet = true;
 
5850
+    return ret;
 
5851
+}
 
5852
+
 
5853
+status_t MediaRecorder::setVideoSize(int width, int height)
 
5854
+{
 
5855
+    ALOGV("setVideoSize(%d, %d)", width, height);
 
5856
+    if (mMediaRecorder == NULL) {
 
5857
+        ALOGE("media recorder is not initialized yet");
 
5858
+        return INVALID_OPERATION;
 
5859
+    }
 
5860
+    if (!(mCurrentState & MEDIA_RECORDER_DATASOURCE_CONFIGURED)) {
 
5861
+        ALOGE("setVideoSize called in an invalid state: %d", mCurrentState);
 
5862
+        return INVALID_OPERATION;
 
5863
+    }
 
5864
+    if (!mIsVideoSourceSet) {
 
5865
+        ALOGE("Cannot set video size without setting video source first");
 
5866
+        return INVALID_OPERATION;
 
5867
+    }
 
5868
+
 
5869
+    status_t ret = mMediaRecorder->setVideoSize(width, height);
 
5870
+    if (OK != ret) {
 
5871
+        ALOGE("setVideoSize failed: %d", ret);
 
5872
+        mCurrentState = MEDIA_RECORDER_ERROR;
 
5873
+        return ret;
 
5874
+    }
 
5875
+
 
5876
+    return ret;
 
5877
+}
 
5878
+
 
5879
+// Query a SurfaceMediaSurface through the Mediaserver, over the
 
5880
+// binder interface. This is used by the Filter Framework (MediaEncoder)
 
5881
+// to get an <IGraphicBufferProducer> object to hook up to ANativeWindow.
 
5882
+sp<IGraphicBufferProducer> MediaRecorder::
 
5883
+        querySurfaceMediaSourceFromMediaServer()
 
5884
+{
 
5885
+    Mutex::Autolock _l(mLock);
 
5886
+    mSurfaceMediaSource =
 
5887
+            mMediaRecorder->querySurfaceMediaSource();
 
5888
+    if (mSurfaceMediaSource == NULL) {
 
5889
+        ALOGE("SurfaceMediaSource could not be initialized!");
 
5890
+    }
 
5891
+    return mSurfaceMediaSource;
 
5892
+}
 
5893
+
 
5894
+status_t MediaRecorder::setVideoFrameRate(int frames_per_second)
 
5895
+{
 
5896
+    ALOGV("setVideoFrameRate(%d)", frames_per_second);
 
5897
+    if (mMediaRecorder == NULL) {
 
5898
+        ALOGE("media recorder is not initialized yet");
 
5899
+        return INVALID_OPERATION;
 
5900
+    }
 
5901
+    if (!(mCurrentState & MEDIA_RECORDER_DATASOURCE_CONFIGURED)) {
 
5902
+        ALOGE("setVideoFrameRate called in an invalid state: %d", mCurrentState);
 
5903
+        return INVALID_OPERATION;
 
5904
+    }
 
5905
+    if (!mIsVideoSourceSet) {
 
5906
+        ALOGE("Cannot set video frame rate without setting video source first");
 
5907
+        return INVALID_OPERATION;
 
5908
+    }
 
5909
+
 
5910
+    status_t ret = mMediaRecorder->setVideoFrameRate(frames_per_second);
 
5911
+    if (OK != ret) {
 
5912
+        ALOGE("setVideoFrameRate failed: %d", ret);
 
5913
+        mCurrentState = MEDIA_RECORDER_ERROR;
 
5914
+        return ret;
 
5915
+    }
 
5916
+    return ret;
 
5917
+}
 
5918
+
 
5919
+status_t MediaRecorder::setParameters(const String8& params) {
 
5920
+    ALOGV("setParameters(%s)", params.string());
 
5921
+    if (mMediaRecorder == NULL) {
 
5922
+        ALOGE("media recorder is not initialized yet");
 
5923
+        return INVALID_OPERATION;
 
5924
+    }
 
5925
+
 
5926
+    bool isInvalidState = (mCurrentState &
 
5927
+                           (MEDIA_RECORDER_PREPARED |
 
5928
+                            MEDIA_RECORDER_RECORDING |
 
5929
+                            MEDIA_RECORDER_ERROR));
 
5930
+    if (isInvalidState) {
 
5931
+        ALOGE("setParameters is called in an invalid state: %d", mCurrentState);
 
5932
+        return INVALID_OPERATION;
 
5933
+    }
 
5934
+
 
5935
+    status_t ret = mMediaRecorder->setParameters(params);
 
5936
+    if (OK != ret) {
 
5937
+        ALOGE("setParameters(%s) failed: %d", params.string(), ret);
 
5938
+        // Do not change our current state to MEDIA_RECORDER_ERROR, failures
 
5939
+        // of the only currently supported parameters, "max-duration" and
 
5940
+        // "max-filesize" are _not_ fatal.
 
5941
+    }
 
5942
+
 
5943
+    return ret;
 
5944
+}
 
5945
+
 
5946
+status_t MediaRecorder::prepare()
 
5947
+{
 
5948
+    ALOGV("prepare");
 
5949
+    if (mMediaRecorder == NULL) {
 
5950
+        ALOGE("media recorder is not initialized yet");
 
5951
+        return INVALID_OPERATION;
 
5952
+    }
 
5953
+    if (!(mCurrentState & MEDIA_RECORDER_DATASOURCE_CONFIGURED)) {
 
5954
+        ALOGE("prepare called in an invalid state: %d", mCurrentState);
 
5955
+        return INVALID_OPERATION;
 
5956
+    }
 
5957
+    if (mIsAudioSourceSet != mIsAudioEncoderSet) {
 
5958
+        if (mIsAudioSourceSet) {
 
5959
+            ALOGE("audio source is set, but audio encoder is not set");
 
5960
+        } else {  // must not happen, since setAudioEncoder checks this already
 
5961
+            ALOGE("audio encoder is set, but audio source is not set");
 
5962
+        }
 
5963
+        return INVALID_OPERATION;
 
5964
+    }
 
5965
+
 
5966
+    if (mIsVideoSourceSet != mIsVideoEncoderSet) {
 
5967
+        if (mIsVideoSourceSet) {
 
5968
+            ALOGE("video source is set, but video encoder is not set");
 
5969
+        } else {  // must not happen, since setVideoEncoder checks this already
 
5970
+            ALOGE("video encoder is set, but video source is not set");
 
5971
+        }
 
5972
+        return INVALID_OPERATION;
 
5973
+    }
 
5974
+
 
5975
+    status_t ret = mMediaRecorder->prepare();
 
5976
+    if (OK != ret) {
 
5977
+        ALOGE("prepare failed: %d", ret);
 
5978
+        mCurrentState = MEDIA_RECORDER_ERROR;
 
5979
+        return ret;
 
5980
+    }
 
5981
+    mCurrentState = MEDIA_RECORDER_PREPARED;
 
5982
+    return ret;
 
5983
+}
 
5984
+
 
5985
+status_t MediaRecorder::getMaxAmplitude(int* max)
 
5986
+{
 
5987
+    ALOGV("getMaxAmplitude");
 
5988
+    if (mMediaRecorder == NULL) {
 
5989
+        ALOGE("media recorder is not initialized yet");
 
5990
+        return INVALID_OPERATION;
 
5991
+    }
 
5992
+    if (mCurrentState & MEDIA_RECORDER_ERROR) {
 
5993
+        ALOGE("getMaxAmplitude called in an invalid state: %d", mCurrentState);
 
5994
+        return INVALID_OPERATION;
 
5995
+    }
 
5996
+
 
5997
+    status_t ret = mMediaRecorder->getMaxAmplitude(max);
 
5998
+    if (OK != ret) {
 
5999
+        ALOGE("getMaxAmplitude failed: %d", ret);
 
6000
+        mCurrentState = MEDIA_RECORDER_ERROR;
 
6001
+        return ret;
 
6002
+    }
 
6003
+    return ret;
 
6004
+}
 
6005
+
 
6006
+status_t MediaRecorder::start()
 
6007
+{
 
6008
+    ALOGV("start");
 
6009
+    if (mMediaRecorder == NULL) {
 
6010
+        ALOGE("media recorder is not initialized yet");
 
6011
+        return INVALID_OPERATION;
 
6012
+    }
 
6013
+    if (!(mCurrentState & MEDIA_RECORDER_PREPARED)) {
 
6014
+        ALOGE("start called in an invalid state: %d", mCurrentState);
 
6015
+        return INVALID_OPERATION;
 
6016
+    }
 
6017
+
 
6018
+    status_t ret = mMediaRecorder->start();
 
6019
+    if (OK != ret) {
 
6020
+        ALOGE("start failed: %d", ret);
 
6021
+        mCurrentState = MEDIA_RECORDER_ERROR;
 
6022
+        return ret;
 
6023
+    }
 
6024
+    mCurrentState = MEDIA_RECORDER_RECORDING;
 
6025
+    return ret;
 
6026
+}
 
6027
+
 
6028
+status_t MediaRecorder::stop()
 
6029
+{
 
6030
+    ALOGV("stop");
 
6031
+    if (mMediaRecorder == NULL) {
 
6032
+        ALOGE("media recorder is not initialized yet");
 
6033
+        return INVALID_OPERATION;
 
6034
+    }
 
6035
+    if (!(mCurrentState & MEDIA_RECORDER_RECORDING)) {
 
6036
+        ALOGE("stop called in an invalid state: %d", mCurrentState);
 
6037
+        return INVALID_OPERATION;
 
6038
+    }
 
6039
+
 
6040
+    status_t ret = mMediaRecorder->stop();
 
6041
+    if (OK != ret) {
 
6042
+        ALOGE("stop failed: %d", ret);
 
6043
+        mCurrentState = MEDIA_RECORDER_ERROR;
 
6044
+        return ret;
 
6045
+    }
 
6046
+
 
6047
+    // FIXME:
 
6048
+    // stop and reset are semantically different.
 
6049
+    // We treat them the same for now, and will change this in the future.
 
6050
+    doCleanUp();
 
6051
+    mCurrentState = MEDIA_RECORDER_IDLE;
 
6052
+    return ret;
 
6053
+}
 
6054
+
 
6055
+// Reset should be OK in any state
 
6056
+status_t MediaRecorder::reset()
 
6057
+{
 
6058
+    ALOGV("reset");
 
6059
+    if (mMediaRecorder == NULL) {
 
6060
+        ALOGE("media recorder is not initialized yet");
 
6061
+        return INVALID_OPERATION;
 
6062
+    }
 
6063
+
 
6064
+    doCleanUp();
 
6065
+    status_t ret = UNKNOWN_ERROR;
 
6066
+    switch (mCurrentState) {
 
6067
+        case MEDIA_RECORDER_IDLE:
 
6068
+            ret = OK;
 
6069
+            break;
 
6070
+
 
6071
+        case MEDIA_RECORDER_RECORDING:
 
6072
+        case MEDIA_RECORDER_DATASOURCE_CONFIGURED:
 
6073
+        case MEDIA_RECORDER_PREPARED:
 
6074
+        case MEDIA_RECORDER_ERROR: {
 
6075
+            ret = doReset();
 
6076
+            if (OK != ret) {
 
6077
+                return ret;  // No need to continue
 
6078
+            }
 
6079
+        }  // Intentional fall through
 
6080
+        case MEDIA_RECORDER_INITIALIZED:
 
6081
+            ret = close();
 
6082
+            break;
 
6083
+
 
6084
+        default: {
 
6085
+            ALOGE("Unexpected non-existing state: %d", mCurrentState);
 
6086
+            break;
 
6087
+        }
 
6088
+    }
 
6089
+    return ret;
 
6090
+}
 
6091
+
 
6092
+status_t MediaRecorder::close()
 
6093
+{
 
6094
+    ALOGV("close");
 
6095
+    if (!(mCurrentState & MEDIA_RECORDER_INITIALIZED)) {
 
6096
+        ALOGE("close called in an invalid state: %d", mCurrentState);
 
6097
+        return INVALID_OPERATION;
 
6098
+    }
 
6099
+    status_t ret = mMediaRecorder->close();
 
6100
+    if (OK != ret) {
 
6101
+        ALOGE("close failed: %d", ret);
 
6102
+        mCurrentState = MEDIA_RECORDER_ERROR;
 
6103
+        return UNKNOWN_ERROR;
 
6104
+    } else {
 
6105
+        mCurrentState = MEDIA_RECORDER_IDLE;
 
6106
+    }
 
6107
+    return ret;
 
6108
+}
 
6109
+
 
6110
+status_t MediaRecorder::doReset()
 
6111
+{
 
6112
+    ALOGV("doReset");
 
6113
+    status_t ret = mMediaRecorder->reset();
 
6114
+    if (OK != ret) {
 
6115
+        ALOGE("doReset failed: %d", ret);
 
6116
+        mCurrentState = MEDIA_RECORDER_ERROR;
 
6117
+        return ret;
 
6118
+    } else {
 
6119
+        mCurrentState = MEDIA_RECORDER_INITIALIZED;
 
6120
+    }
 
6121
+    return ret;
 
6122
+}
 
6123
+
 
6124
+void MediaRecorder::doCleanUp()
 
6125
+{
 
6126
+    ALOGV("doCleanUp");
 
6127
+    mIsAudioSourceSet  = false;
 
6128
+    mIsVideoSourceSet  = false;
 
6129
+    mIsAudioEncoderSet = false;
 
6130
+    mIsVideoEncoderSet = false;
 
6131
+    mIsOutputFileSet   = false;
 
6132
+}
 
6133
+
 
6134
+// Release should be OK in any state
 
6135
+status_t MediaRecorder::release()
 
6136
+{
 
6137
+    ALOGV("release");
 
6138
+    if (mMediaRecorder != NULL) {
 
6139
+        return mMediaRecorder->release();
 
6140
+    }
 
6141
+    return INVALID_OPERATION;
 
6142
+}
 
6143
+
 
6144
+
 
6145
+MediaRecorder::MediaRecorder()
 
6146
+    : mMediaRecorderFactory(NULL),
 
6147
+    mSurfaceMediaSource(NULL)
 
6148
+{
 
6149
+    ALOGV("constructor (custom)");
 
6150
+
 
6151
+    if (mMediaRecorderFactory == NULL) {
 
6152
+        sp<IServiceManager> sm = defaultServiceManager();
 
6153
+        sp<IBinder> binder;
 
6154
+        do {
 
6155
+            binder = sm->getService(String16(IMediaRecorderFactory::exported_service_name()));
 
6156
+            if (binder != 0) {
 
6157
+                break;
 
6158
+            }
 
6159
+            ALOGW("MediaRecorderFactory service not published, waiting...");
 
6160
+            usleep(500000); // 0.5 s
 
6161
+        } while (true);
 
6162
+
 
6163
+        mMediaRecorderFactory = interface_cast<IMediaRecorderFactory>(binder);
 
6164
+    }
 
6165
+
 
6166
+    ALOGE_IF(mMediaRecorderFactory == NULL, "no MediaRecorderFactory!?");
 
6167
+
 
6168
+    mMediaRecorder = mMediaRecorderFactory->createMediaRecorder();
 
6169
+    if (mMediaRecorder != NULL) {
 
6170
+        mCurrentState = MEDIA_RECORDER_IDLE;
 
6171
+    }
 
6172
+
 
6173
+    doCleanUp();
 
6174
+}
 
6175
+
 
6176
+status_t MediaRecorder::initCheck()
 
6177
+{
 
6178
+    return mMediaRecorder != 0 ? NO_ERROR : NO_INIT;
 
6179
+}
 
6180
+
 
6181
+MediaRecorder::~MediaRecorder()
 
6182
+{
 
6183
+    ALOGV("destructor");
 
6184
+    if (mMediaRecorder != NULL) {
 
6185
+        mMediaRecorder.clear();
 
6186
+    }
 
6187
+
 
6188
+    if (mSurfaceMediaSource != NULL) {
 
6189
+        mSurfaceMediaSource.clear();
 
6190
+    }
 
6191
+}
 
6192
+
 
6193
+status_t MediaRecorder::setListener(const sp<MediaRecorderListener>& listener)
 
6194
+{
 
6195
+    ALOGV("setListener");
 
6196
+    Mutex::Autolock _l(mLock);
 
6197
+    mListener = listener;
 
6198
+
 
6199
+    return NO_ERROR;
 
6200
+}
 
6201
+
 
6202
+status_t MediaRecorder::setClientName(const String16& clientName)
 
6203
+{
 
6204
+    ALOGV("setClientName");
 
6205
+    if (mMediaRecorder == NULL) {
 
6206
+        ALOGE("media recorder is not initialized yet");
 
6207
+        return INVALID_OPERATION;
 
6208
+    }
 
6209
+    bool isInvalidState = (mCurrentState &
 
6210
+                           (MEDIA_RECORDER_PREPARED |
 
6211
+                            MEDIA_RECORDER_RECORDING |
 
6212
+                            MEDIA_RECORDER_ERROR));
 
6213
+    if (isInvalidState) {
 
6214
+        ALOGE("setClientName is called in an invalid state: %d", mCurrentState);
 
6215
+        return INVALID_OPERATION;
 
6216
+    }
 
6217
+
 
6218
+    mMediaRecorder->setClientName(clientName);
 
6219
+
 
6220
+    return NO_ERROR;
 
6221
+}
 
6222
+
 
6223
+void MediaRecorder::notify(int msg, int ext1, int ext2)
 
6224
+{
 
6225
+    ALOGV("message received msg=%d, ext1=%d, ext2=%d", msg, ext1, ext2);
 
6226
+
 
6227
+    sp<MediaRecorderListener> listener;
 
6228
+    mLock.lock();
 
6229
+    listener = mListener;
 
6230
+    mLock.unlock();
 
6231
+
 
6232
+    if (listener != NULL) {
 
6233
+        Mutex::Autolock _l(mNotifyLock);
 
6234
+        ALOGV("callback application");
 
6235
+        listener->notify(msg, ext1, ext2);
 
6236
+        ALOGV("back from callback");
 
6237
+    }
 
6238
+}
 
6239
+
 
6240
+void MediaRecorder::died()
 
6241
+{
 
6242
+    ALOGV("died");
 
6243
+    notify(MEDIA_RECORDER_EVENT_ERROR, MEDIA_ERROR_SERVER_DIED, 0);
 
6244
+}
 
6245
+
 
6246
+} // namespace android
 
6247
--- /dev/null
 
6248
+++ libhybris-0.1.0+git20131207+e452e83/compat/media/media_recorder.h
 
6249
@@ -0,0 +1,265 @@
 
6250
+/*
 
6251
+ ** Copyright (C) 2008 The Android Open Source Project
 
6252
+ ** Copyright (C) 2014 Canonical Ltd
 
6253
+ **
 
6254
+ ** Adapted from the Android equivalent code for use in Ubuntu.
 
6255
+ **
 
6256
+ ** Licensed under the Apache License, Version 2.0 (the "License");
 
6257
+ ** you may not use this file except in compliance with the License.
 
6258
+ ** You may obtain a copy of the License at
 
6259
+ **
 
6260
+ **     http://www.apache.org/licenses/LICENSE-2.0
 
6261
+ **
 
6262
+ ** Unless required by applicable law or agreed to in writing, software
 
6263
+ ** distributed under the License is distributed on an "AS IS" BASIS,
 
6264
+ ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 
6265
+ ** See the License for the specific language governing permissions and
 
6266
+ **
 
6267
+ ** limitations under the License.
 
6268
+ */
 
6269
+
 
6270
+#ifndef ANDROID_MEDIARECORDER_H
 
6271
+#define ANDROID_MEDIARECORDER_H
 
6272
+
 
6273
+#include <utils/Log.h>
 
6274
+#include <utils/threads.h>
 
6275
+#include <utils/List.h>
 
6276
+#include <utils/Errors.h>
 
6277
+#include <media/IMediaRecorderClient.h>
 
6278
+#include <media/IMediaDeathNotifier.h>
 
6279
+
 
6280
+namespace android {
 
6281
+
 
6282
+class Surface;
 
6283
+class IMediaRecorder;
 
6284
+class IMediaRecorderFactory;
 
6285
+class ICamera;
 
6286
+class ICameraRecordingProxy;
 
6287
+class IGraphicBufferProducer;
 
6288
+class Surface;
 
6289
+
 
6290
+typedef void (*media_completion_f)(status_t status, void *cookie);
 
6291
+
 
6292
+enum video_source {
 
6293
+    VIDEO_SOURCE_DEFAULT = 0,
 
6294
+    VIDEO_SOURCE_CAMERA = 1,
 
6295
+    VIDEO_SOURCE_GRALLOC_BUFFER = 2,
 
6296
+
 
6297
+    VIDEO_SOURCE_LIST_END  // must be last - used to validate audio source type
 
6298
+};
 
6299
+
 
6300
+// Please update media/java/android/media/MediaRecorder.java if the following is updated.
 
6301
+enum output_format {
 
6302
+    OUTPUT_FORMAT_DEFAULT = 0,
 
6303
+    OUTPUT_FORMAT_THREE_GPP = 1,
 
6304
+    OUTPUT_FORMAT_MPEG_4 = 2,
 
6305
+
 
6306
+
 
6307
+    OUTPUT_FORMAT_AUDIO_ONLY_START = 3, // Used in validating the output format.  Should be the
 
6308
+                                        //  at the start of the audio only output formats.
 
6309
+
 
6310
+    /* These are audio only file formats */
 
6311
+    OUTPUT_FORMAT_RAW_AMR = 3, //to be backward compatible
 
6312
+    OUTPUT_FORMAT_AMR_NB = 3,
 
6313
+    OUTPUT_FORMAT_AMR_WB = 4,
 
6314
+    OUTPUT_FORMAT_AAC_ADIF = 5,
 
6315
+    OUTPUT_FORMAT_AAC_ADTS = 6,
 
6316
+
 
6317
+    /* Stream over a socket, limited to a single stream */
 
6318
+    OUTPUT_FORMAT_RTP_AVP = 7,
 
6319
+
 
6320
+    /* H.264/AAC data encapsulated in MPEG2/TS */
 
6321
+    OUTPUT_FORMAT_MPEG2TS = 8,
 
6322
+
 
6323
+    OUTPUT_FORMAT_LIST_END // must be last - used to validate format type
 
6324
+};
 
6325
+
 
6326
+enum audio_encoder {
 
6327
+    AUDIO_ENCODER_DEFAULT = 0,
 
6328
+    AUDIO_ENCODER_AMR_NB = 1,
 
6329
+    AUDIO_ENCODER_AMR_WB = 2,
 
6330
+    AUDIO_ENCODER_AAC = 3,
 
6331
+    AUDIO_ENCODER_HE_AAC = 4,
 
6332
+    AUDIO_ENCODER_AAC_ELD = 5,
 
6333
+
 
6334
+    AUDIO_ENCODER_LIST_END // must be the last - used to validate the audio encoder type
 
6335
+};
 
6336
+
 
6337
+enum video_encoder {
 
6338
+    VIDEO_ENCODER_DEFAULT = 0,
 
6339
+    VIDEO_ENCODER_H263 = 1,
 
6340
+    VIDEO_ENCODER_H264 = 2,
 
6341
+    VIDEO_ENCODER_MPEG_4_SP = 3,
 
6342
+
 
6343
+    VIDEO_ENCODER_LIST_END // must be the last - used to validate the video encoder type
 
6344
+};
 
6345
+
 
6346
+/*
 
6347
+ * The state machine of the media_recorder.
 
6348
+ */
 
6349
+enum media_recorder_states {
 
6350
+    // Error state.
 
6351
+    MEDIA_RECORDER_ERROR                 =      0,
 
6352
+
 
6353
+    // Recorder was just created.
 
6354
+    MEDIA_RECORDER_IDLE                  = 1 << 0,
 
6355
+
 
6356
+    // Recorder has been initialized.
 
6357
+    MEDIA_RECORDER_INITIALIZED           = 1 << 1,
 
6358
+
 
6359
+    // Configuration of the recorder has been completed.
 
6360
+    MEDIA_RECORDER_DATASOURCE_CONFIGURED = 1 << 2,
 
6361
+
 
6362
+    // Recorder is ready to start.
 
6363
+    MEDIA_RECORDER_PREPARED              = 1 << 3,
 
6364
+
 
6365
+    // Recording is in progress.
 
6366
+    MEDIA_RECORDER_RECORDING             = 1 << 4,
 
6367
+};
 
6368
+
 
6369
+// The "msg" code passed to the listener in notify.
 
6370
+enum media_recorder_event_type {
 
6371
+    MEDIA_RECORDER_EVENT_LIST_START               = 1,
 
6372
+    MEDIA_RECORDER_EVENT_ERROR                    = 1,
 
6373
+    MEDIA_RECORDER_EVENT_INFO                     = 2,
 
6374
+    MEDIA_RECORDER_EVENT_LIST_END                 = 99,
 
6375
+
 
6376
+    // Track related event types
 
6377
+    MEDIA_RECORDER_TRACK_EVENT_LIST_START         = 100,
 
6378
+    MEDIA_RECORDER_TRACK_EVENT_ERROR              = 100,
 
6379
+    MEDIA_RECORDER_TRACK_EVENT_INFO               = 101,
 
6380
+    MEDIA_RECORDER_TRACK_EVENT_LIST_END           = 1000,
 
6381
+};
 
6382
+
 
6383
+/*
 
6384
+ * The (part of) "what" code passed to the listener in notify.
 
6385
+ * When the error or info type is track specific, the what has
 
6386
+ * the following layout:
 
6387
+ * the left-most 16-bit is meant for error or info type.
 
6388
+ * the right-most 4-bit is meant for track id.
 
6389
+ * the rest is reserved.
 
6390
+ *
 
6391
+ * | track id | reserved |     error or info type     |
 
6392
+ * 31         28         16                           0
 
6393
+ *
 
6394
+ */
 
6395
+enum media_recorder_error_type {
 
6396
+    MEDIA_RECORDER_ERROR_UNKNOWN                   = 1,
 
6397
+
 
6398
+    // Track related error type
 
6399
+    MEDIA_RECORDER_TRACK_ERROR_LIST_START          = 100,
 
6400
+    MEDIA_RECORDER_TRACK_ERROR_GENERAL             = 100,
 
6401
+    MEDIA_RECORDER_ERROR_VIDEO_NO_SYNC_FRAME       = 200,
 
6402
+    MEDIA_RECORDER_TRACK_ERROR_LIST_END            = 1000,
 
6403
+};
 
6404
+
 
6405
+// The codes are distributed as follow:
 
6406
+//   0xx: Reserved
 
6407
+//   8xx: General info/warning
 
6408
+//
 
6409
+enum media_recorder_info_type {
 
6410
+    MEDIA_RECORDER_INFO_UNKNOWN                   = 1,
 
6411
+
 
6412
+    MEDIA_RECORDER_INFO_MAX_DURATION_REACHED      = 800,
 
6413
+    MEDIA_RECORDER_INFO_MAX_FILESIZE_REACHED      = 801,
 
6414
+
 
6415
+    // All track related informtional events start here
 
6416
+    MEDIA_RECORDER_TRACK_INFO_LIST_START           = 1000,
 
6417
+    MEDIA_RECORDER_TRACK_INFO_COMPLETION_STATUS    = 1000,
 
6418
+    MEDIA_RECORDER_TRACK_INFO_PROGRESS_IN_TIME     = 1001,
 
6419
+    MEDIA_RECORDER_TRACK_INFO_TYPE                 = 1002,
 
6420
+    MEDIA_RECORDER_TRACK_INFO_DURATION_MS          = 1003,
 
6421
+
 
6422
+    // The time to measure the max chunk duration
 
6423
+    MEDIA_RECORDER_TRACK_INFO_MAX_CHUNK_DUR_MS     = 1004,
 
6424
+
 
6425
+    MEDIA_RECORDER_TRACK_INFO_ENCODED_FRAMES       = 1005,
 
6426
+
 
6427
+    // The time to measure how well the audio and video
 
6428
+    // track data is interleaved.
 
6429
+    MEDIA_RECORDER_TRACK_INTER_CHUNK_TIME_MS       = 1006,
 
6430
+
 
6431
+    // The time to measure system response. Note that
 
6432
+    // the delay does not include the intentional delay
 
6433
+    // we use to eliminate the recording sound.
 
6434
+    MEDIA_RECORDER_TRACK_INFO_INITIAL_DELAY_MS     = 1007,
 
6435
+
 
6436
+    // The time used to compensate for initial A/V sync.
 
6437
+    MEDIA_RECORDER_TRACK_INFO_START_OFFSET_MS      = 1008,
 
6438
+
 
6439
+    // Total number of bytes of the media data.
 
6440
+    MEDIA_RECORDER_TRACK_INFO_DATA_KBYTES          = 1009,
 
6441
+
 
6442
+    MEDIA_RECORDER_TRACK_INFO_LIST_END             = 2000,
 
6443
+};
 
6444
+
 
6445
+class MediaPlayerService;
 
6446
+
 
6447
+// ----------------------------------------------------------------------------
 
6448
+// ref-counted object for callbacks
 
6449
+class MediaRecorderListener: virtual public RefBase
 
6450
+{
 
6451
+public:
 
6452
+    virtual void notify(int msg, int ext1, int ext2) = 0;
 
6453
+};
 
6454
+
 
6455
+class MediaRecorder : public BnMediaRecorderClient,
 
6456
+                      public virtual IMediaDeathNotifier
 
6457
+{
 
6458
+public:
 
6459
+    MediaRecorder();
 
6460
+    ~MediaRecorder();
 
6461
+
 
6462
+    void        died();
 
6463
+    status_t    initCheck();
 
6464
+    status_t    setCamera(const sp<ICamera>& camera, const sp<ICameraRecordingProxy>& proxy);
 
6465
+    status_t    setPreviewSurface(const sp<IGraphicBufferProducer>& surface);
 
6466
+    status_t    setVideoSource(int vs);
 
6467
+    status_t    setAudioSource(int as);
 
6468
+    status_t    setOutputFormat(int of);
 
6469
+    status_t    setVideoEncoder(int ve);
 
6470
+    status_t    setAudioEncoder(int ae);
 
6471
+    status_t    setOutputFile(const char* path);
 
6472
+    status_t    setOutputFile(int fd, int64_t offset, int64_t length);
 
6473
+    status_t    setVideoSize(int width, int height);
 
6474
+    status_t    setVideoFrameRate(int frames_per_second);
 
6475
+    status_t    setParameters(const String8& params);
 
6476
+    status_t    setListener(const sp<MediaRecorderListener>& listener);
 
6477
+    status_t    setClientName(const String16& clientName);
 
6478
+    status_t    prepare();
 
6479
+    status_t    getMaxAmplitude(int* max);
 
6480
+    status_t    start();
 
6481
+    status_t    stop();
 
6482
+    status_t    reset();
 
6483
+    status_t    init();
 
6484
+    status_t    close();
 
6485
+    status_t    release();
 
6486
+    void        notify(int msg, int ext1, int ext2);
 
6487
+    sp<IGraphicBufferProducer>     querySurfaceMediaSourceFromMediaServer();
 
6488
+
 
6489
+private:
 
6490
+    void                    doCleanUp();
 
6491
+    status_t                doReset();
 
6492
+
 
6493
+    sp<IMediaRecorder>          mMediaRecorder;
 
6494
+    sp<MediaRecorderListener>   mListener;
 
6495
+    sp<IMediaRecorderFactory>    mMediaRecorderFactory;
 
6496
+
 
6497
+    // Reference to IGraphicBufferProducer
 
6498
+    // for encoding GL Frames. That is useful only when the
 
6499
+    // video source is set to VIDEO_SOURCE_GRALLOC_BUFFER
 
6500
+    sp<IGraphicBufferProducer>  mSurfaceMediaSource;
 
6501
+
 
6502
+    media_recorder_states       mCurrentState;
 
6503
+    bool                        mIsAudioSourceSet;
 
6504
+    bool                        mIsVideoSourceSet;
 
6505
+    bool                        mIsAudioEncoderSet;
 
6506
+    bool                        mIsVideoEncoderSet;
 
6507
+    bool                        mIsOutputFileSet;
 
6508
+    Mutex                       mLock;
 
6509
+    Mutex                       mNotifyLock;
 
6510
+};
 
6511
+
 
6512
+};  // namespace android
 
6513
+
 
6514
+#endif // ANDROID_MEDIARECORDER_H
 
6515
--- /dev/null
 
6516
+++ libhybris-0.1.0+git20131207+e452e83/compat/media/media_recorder_client.cpp
 
6517
@@ -0,0 +1,305 @@
 
6518
+/*
 
6519
+ * Copyright (C) 2013-2014 Canonical Ltd
 
6520
+ *
 
6521
+ * Licensed under the Apache License, Version 2.0 (the "License");
 
6522
+ * you may not use this file except in compliance with the License.
 
6523
+ * You may obtain a copy of the License at
 
6524
+ *
 
6525
+ *      http://www.apache.org/licenses/LICENSE-2.0
 
6526
+ *
 
6527
+ * Unless required by applicable law or agreed to in writing, software
 
6528
+ * distributed under the License is distributed on an "AS IS" BASIS,
 
6529
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 
6530
+ * See the License for the specific language governing permissions and
 
6531
+ * limitations under the License.
 
6532
+ *
 
6533
+ * Authored by: Jim Hodapp <jim.hodapp@canonical.com>
 
6534
+ */
 
6535
+
 
6536
+#include "media_recorder_client.h"
 
6537
+
 
6538
+#include <libmediaplayerservice/StagefrightRecorder.h>
 
6539
+
 
6540
+#include <utils/Log.h>
 
6541
+
 
6542
+#define LOG_NDEBUG 0
 
6543
+#define LOG_TAG "MediaRecorderClient"
 
6544
+
 
6545
+#define REPORT_FUNCTION() ALOGV("%s \n", __PRETTY_FUNCTION__)
 
6546
+
 
6547
+using namespace android;
 
6548
+
 
6549
+MediaRecorderClient::MediaRecorderClient()
 
6550
+{
 
6551
+    REPORT_FUNCTION();
 
6552
+    recorder = new android::StagefrightRecorder;
 
6553
+}
 
6554
+
 
6555
+MediaRecorderClient::~MediaRecorderClient()
 
6556
+{
 
6557
+    REPORT_FUNCTION();
 
6558
+    release();
 
6559
+}
 
6560
+
 
6561
+status_t MediaRecorderClient::setCamera(const sp<android::ICamera>& camera,
 
6562
+        const sp<ICameraRecordingProxy>& proxy)
 
6563
+{
 
6564
+    REPORT_FUNCTION();
 
6565
+    Mutex::Autolock lock(recorder_lock);
 
6566
+    if (recorder == NULL) {
 
6567
+        ALOGE("recorder must not be NULL");
 
6568
+        return NO_INIT;
 
6569
+    }
 
6570
+    return recorder->setCamera(camera, proxy);
 
6571
+}
 
6572
+
 
6573
+status_t MediaRecorderClient::setPreviewSurface(const android::sp<android::IGraphicBufferProducer>& surface)
 
6574
+{
 
6575
+    REPORT_FUNCTION();
 
6576
+    Mutex::Autolock lock(recorder_lock);
 
6577
+    if (recorder == NULL) {
 
6578
+        ALOGE("recorder must not be NULL");
 
6579
+        return NO_INIT;
 
6580
+    }
 
6581
+    return recorder->setPreviewSurface(surface);
 
6582
+}
 
6583
+
 
6584
+status_t MediaRecorderClient::setVideoSource(int vs)
 
6585
+{
 
6586
+    REPORT_FUNCTION();
 
6587
+    Mutex::Autolock lock(recorder_lock);
 
6588
+    if (recorder == NULL)     {
 
6589
+        ALOGE("recorder must not be NULL");
 
6590
+        return NO_INIT;
 
6591
+    }
 
6592
+    return recorder->setVideoSource((android::video_source)vs);
 
6593
+}
 
6594
+
 
6595
+status_t MediaRecorderClient::setAudioSource(int as)
 
6596
+{
 
6597
+    REPORT_FUNCTION();
 
6598
+    Mutex::Autolock lock(recorder_lock);
 
6599
+    if (recorder == NULL)  {
 
6600
+        ALOGE("recorder must not be NULL");
 
6601
+        return NO_INIT;
 
6602
+    }
 
6603
+    return recorder->setAudioSource((audio_source_t)as);
 
6604
+}
 
6605
+
 
6606
+status_t MediaRecorderClient::setOutputFormat(int of)
 
6607
+{
 
6608
+    REPORT_FUNCTION();
 
6609
+    Mutex::Autolock lock(recorder_lock);
 
6610
+    if (recorder == NULL) {
 
6611
+        ALOGE("recorder must not be NULL");
 
6612
+        return NO_INIT;
 
6613
+    }
 
6614
+    return recorder->setOutputFormat((android::output_format)of);
 
6615
+}
 
6616
+
 
6617
+status_t MediaRecorderClient::setVideoEncoder(int ve)
 
6618
+{
 
6619
+    REPORT_FUNCTION();
 
6620
+    Mutex::Autolock lock(recorder_lock);
 
6621
+    if (recorder == NULL) {
 
6622
+        ALOGE("recorder must not be NULL");
 
6623
+        return NO_INIT;
 
6624
+    }
 
6625
+    return recorder->setVideoEncoder((android::video_encoder)ve);
 
6626
+}
 
6627
+
 
6628
+status_t MediaRecorderClient::setAudioEncoder(int ae)
 
6629
+{
 
6630
+    REPORT_FUNCTION();
 
6631
+    Mutex::Autolock lock(recorder_lock);
 
6632
+    if (recorder == NULL) {
 
6633
+        ALOGE("recorder must not be NULL");
 
6634
+        return NO_INIT;
 
6635
+    }
 
6636
+    return recorder->setAudioEncoder((android::audio_encoder)ae);
 
6637
+}
 
6638
+
 
6639
+status_t MediaRecorderClient::setOutputFile(const char* path)
 
6640
+{
 
6641
+    REPORT_FUNCTION();
 
6642
+    Mutex::Autolock lock(recorder_lock);
 
6643
+    if (recorder == NULL) {
 
6644
+        ALOGE("recorder must not be NULL");
 
6645
+        return NO_INIT;
 
6646
+    }
 
6647
+    return recorder->setOutputFile(path);
 
6648
+}
 
6649
+
 
6650
+status_t MediaRecorderClient::setOutputFile(int fd, int64_t offset, int64_t length)
 
6651
+{
 
6652
+    REPORT_FUNCTION();
 
6653
+    Mutex::Autolock lock(recorder_lock);
 
6654
+    if (recorder == NULL) {
 
6655
+        ALOGE("recorder must not be NULL");
 
6656
+        return NO_INIT;
 
6657
+    }
 
6658
+    return recorder->setOutputFile(fd, offset, length);
 
6659
+}
 
6660
+
 
6661
+status_t MediaRecorderClient::setVideoSize(int width, int height)
 
6662
+{
 
6663
+    REPORT_FUNCTION();
 
6664
+    Mutex::Autolock lock(recorder_lock);
 
6665
+    if (recorder == NULL) {
 
6666
+        ALOGE("recorder must not be NULL");
 
6667
+        return NO_INIT;
 
6668
+    }
 
6669
+    return recorder->setVideoSize(width, height);
 
6670
+}
 
6671
+
 
6672
+status_t MediaRecorderClient::setVideoFrameRate(int frames_per_second)
 
6673
+{
 
6674
+    REPORT_FUNCTION();
 
6675
+    Mutex::Autolock lock(recorder_lock);
 
6676
+    if (recorder == NULL) {
 
6677
+        ALOGE("recorder must not be NULL");
 
6678
+        return NO_INIT;
 
6679
+    }
 
6680
+    return recorder->setVideoFrameRate(frames_per_second);
 
6681
+}
 
6682
+
 
6683
+status_t MediaRecorderClient::setParameters(const android::String8& params)
 
6684
+{
 
6685
+    REPORT_FUNCTION();
 
6686
+    Mutex::Autolock lock(recorder_lock);
 
6687
+    if (recorder == NULL) {
 
6688
+        ALOGE("recorder must not be NULL");
 
6689
+        return NO_INIT;
 
6690
+    }
 
6691
+    return recorder->setParameters(params);
 
6692
+}
 
6693
+
 
6694
+status_t MediaRecorderClient::setListener(const android::sp<android::IMediaRecorderClient>& listener)
 
6695
+{
 
6696
+    REPORT_FUNCTION();
 
6697
+    Mutex::Autolock lock(recorder_lock);
 
6698
+    if (recorder == NULL) {
 
6699
+        ALOGE("recorder must not be NULL");
 
6700
+        return NO_INIT;
 
6701
+    }
 
6702
+    return recorder->setListener(listener);
 
6703
+}
 
6704
+
 
6705
+status_t MediaRecorderClient::setClientName(const android::String16& clientName)
 
6706
+{
 
6707
+    REPORT_FUNCTION();
 
6708
+    Mutex::Autolock lock(recorder_lock);
 
6709
+    if (recorder == NULL) {
 
6710
+        ALOGE("recorder must not be NULL");
 
6711
+        return NO_INIT;
 
6712
+    }
 
6713
+    return recorder->setClientName(clientName);
 
6714
+}
 
6715
+
 
6716
+status_t MediaRecorderClient::prepare()
 
6717
+{
 
6718
+    REPORT_FUNCTION();
 
6719
+    Mutex::Autolock lock(recorder_lock);
 
6720
+    if (recorder == NULL) {
 
6721
+        ALOGE("recorder must not be NULL");
 
6722
+        return NO_INIT;
 
6723
+    }
 
6724
+    return recorder->prepare();
 
6725
+}
 
6726
+
 
6727
+status_t MediaRecorderClient::getMaxAmplitude(int* max)
 
6728
+{
 
6729
+    REPORT_FUNCTION();
 
6730
+    Mutex::Autolock lock(recorder_lock);
 
6731
+    if (recorder == NULL) {
 
6732
+        ALOGE("recorder must not be NULL");
 
6733
+        return NO_INIT;
 
6734
+    }
 
6735
+    return recorder->getMaxAmplitude(max);
 
6736
+}
 
6737
+
 
6738
+status_t MediaRecorderClient::start()
 
6739
+{
 
6740
+    REPORT_FUNCTION();
 
6741
+    Mutex::Autolock lock(recorder_lock);
 
6742
+    if (recorder == NULL) {
 
6743
+        ALOGE("recorder must not be NULL");
 
6744
+        return NO_INIT;
 
6745
+    }
 
6746
+    return recorder->start();
 
6747
+}
 
6748
+
 
6749
+status_t MediaRecorderClient::stop()
 
6750
+{
 
6751
+    REPORT_FUNCTION();
 
6752
+    Mutex::Autolock lock(recorder_lock);
 
6753
+    if (recorder == NULL) {
 
6754
+        ALOGE("recorder must not be NULL");
 
6755
+        return NO_INIT;
 
6756
+    }
 
6757
+    return recorder->stop();
 
6758
+}
 
6759
+
 
6760
+status_t MediaRecorderClient::reset()
 
6761
+{
 
6762
+    REPORT_FUNCTION();
 
6763
+    Mutex::Autolock lock(recorder_lock);
 
6764
+    if (recorder == NULL) {
 
6765
+        ALOGE("recorder must not be NULL");
 
6766
+        return NO_INIT;
 
6767
+    }
 
6768
+    return recorder->reset();
 
6769
+}
 
6770
+
 
6771
+status_t MediaRecorderClient::init()
 
6772
+{
 
6773
+    REPORT_FUNCTION();
 
6774
+    Mutex::Autolock lock(recorder_lock);
 
6775
+    if (recorder == NULL) {
 
6776
+        ALOGE("recorder must not be NULL");
 
6777
+        return NO_INIT;
 
6778
+    }
 
6779
+    return recorder->init();
 
6780
+}
 
6781
+
 
6782
+status_t MediaRecorderClient::close()
 
6783
+{
 
6784
+    REPORT_FUNCTION();
 
6785
+    Mutex::Autolock lock(recorder_lock);
 
6786
+    if (recorder == NULL) {
 
6787
+        ALOGE("recorder must not be NULL");
 
6788
+        return NO_INIT;
 
6789
+    }
 
6790
+    return recorder->close();
 
6791
+}
 
6792
+
 
6793
+status_t MediaRecorderClient::release()
 
6794
+{
 
6795
+    REPORT_FUNCTION();
 
6796
+    Mutex::Autolock lock(recorder_lock);
 
6797
+    if (recorder != NULL) {
 
6798
+        delete recorder;
 
6799
+        recorder = NULL;
 
6800
+    }
 
6801
+    return NO_ERROR;
 
6802
+}
 
6803
+
 
6804
+status_t MediaRecorderClient::dump(int fd, const Vector<String16>& args) const
 
6805
+{
 
6806
+    REPORT_FUNCTION();
 
6807
+    if (recorder != NULL) {
 
6808
+        return recorder->dump(fd, args);
 
6809
+    }
 
6810
+    return android::OK;
 
6811
+}
 
6812
+
 
6813
+sp<IGraphicBufferProducer> MediaRecorderClient::querySurfaceMediaSource()
 
6814
+{
 
6815
+    REPORT_FUNCTION();
 
6816
+    Mutex::Autolock lock(recorder_lock);
 
6817
+    if (recorder == NULL) {
 
6818
+        ALOGE("recorder is not initialized");
 
6819
+        return NULL;
 
6820
+    }
 
6821
+    return recorder->querySurfaceMediaSource();
 
6822
+}
 
6823
--- /dev/null
 
6824
+++ libhybris-0.1.0+git20131207+e452e83/compat/media/media_recorder_client.h
 
6825
@@ -0,0 +1,74 @@
 
6826
+/*
 
6827
+ * Copyright (C) 2013-2014 Canonical Ltd
 
6828
+ *
 
6829
+ * Licensed under the Apache License, Version 2.0 (the "License");
 
6830
+ * you may not use this file except in compliance with the License.
 
6831
+ * You may obtain a copy of the License at
 
6832
+ *
 
6833
+ *      http://www.apache.org/licenses/LICENSE-2.0
 
6834
+ *
 
6835
+ * Unless required by applicable law or agreed to in writing, software
 
6836
+ * distributed under the License is distributed on an "AS IS" BASIS,
 
6837
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 
6838
+ * See the License for the specific language governing permissions and
 
6839
+ * limitations under the License.
 
6840
+ *
 
6841
+ * Authored by: Jim Hodapp <jim.hodapp@canonical.com>
 
6842
+ */
 
6843
+
 
6844
+#ifndef MEDIA_RECORDER_CLIENT_H_
 
6845
+#define MEDIA_RECORDER_CLIENT_H_
 
6846
+
 
6847
+#include <hybris/internal/camera_control.h>
 
6848
+#include <hybris/media/media_recorder_layer.h>
 
6849
+
 
6850
+#include <media/IMediaRecorder.h>
 
6851
+
 
6852
+namespace android {
 
6853
+
 
6854
+class MediaRecorderBase;
 
6855
+class Mutex;
 
6856
+
 
6857
+/*!
 
6858
+ * \brief The MediaRecorderClient struct wraps the service side of the MediaRecorder class
 
6859
+ */
 
6860
+struct MediaRecorderClient : public BnMediaRecorder
 
6861
+{
 
6862
+public:
 
6863
+    MediaRecorderClient();
 
6864
+    virtual ~MediaRecorderClient();
 
6865
+
 
6866
+    virtual status_t setCamera(const sp<ICamera>& camera,
 
6867
+            const sp<ICameraRecordingProxy>& proxy);
 
6868
+    virtual status_t setPreviewSurface(const sp<IGraphicBufferProducer>& surface);
 
6869
+    virtual status_t setVideoSource(int vs);
 
6870
+    virtual status_t setAudioSource(int as);
 
6871
+    virtual status_t setOutputFormat(int of);
 
6872
+    virtual status_t setVideoEncoder(int ve);
 
6873
+    virtual status_t setAudioEncoder(int ae);
 
6874
+    virtual status_t setOutputFile(const char* path);
 
6875
+    virtual status_t setOutputFile(int fd, int64_t offset, int64_t length);
 
6876
+    virtual status_t setVideoSize(int width, int height);
 
6877
+    virtual status_t setVideoFrameRate(int frames_per_second);
 
6878
+    virtual status_t setParameters(const String8& params);
 
6879
+    virtual status_t setListener(const sp<IMediaRecorderClient>& listener);
 
6880
+    virtual status_t setClientName(const String16& clientName);
 
6881
+    virtual status_t prepare();
 
6882
+    virtual status_t getMaxAmplitude(int* max);
 
6883
+    virtual status_t start();
 
6884
+    virtual status_t stop();
 
6885
+    virtual status_t reset();
 
6886
+    virtual status_t init();
 
6887
+    virtual status_t close();
 
6888
+    virtual status_t release();
 
6889
+    virtual status_t dump(int fd, const Vector<String16>& args) const;
 
6890
+    virtual sp<IGraphicBufferProducer> querySurfaceMediaSource();
 
6891
+
 
6892
+private:
 
6893
+    MediaRecorderBase *recorder;
 
6894
+    Mutex recorder_lock;
 
6895
+};
 
6896
+
 
6897
+}
 
6898
+
 
6899
+#endif
 
6900
--- /dev/null
 
6901
+++ libhybris-0.1.0+git20131207+e452e83/compat/media/media_recorder_factory.cpp
 
6902
@@ -0,0 +1,133 @@
 
6903
+/*
 
6904
+ * Copyright (C) 2014 Canonical Ltd
 
6905
+ *
 
6906
+ * Licensed under the Apache License, Version 2.0 (the "License");
 
6907
+ * you may not use this file except in compliance with the License.
 
6908
+ * You may obtain a copy of the License at
 
6909
+ *
 
6910
+ *      http://www.apache.org/licenses/LICENSE-2.0
 
6911
+ *
 
6912
+ * Unless required by applicable law or agreed to in writing, software
 
6913
+ * distributed under the License is distributed on an "AS IS" BASIS,
 
6914
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 
6915
+ * See the License for the specific language governing permissions and
 
6916
+ * limitations under the License.
 
6917
+ *
 
6918
+ * Authored by: Jim Hodapp <jim.hodapp@canonical.com>
 
6919
+ */
 
6920
+
 
6921
+//#define LOG_NDEBUG 0
 
6922
+#undef LOG_TAG
 
6923
+#define LOG_TAG "MediaRecorderFactory"
 
6924
+
 
6925
+#include "media_recorder_factory.h"
 
6926
+#include "media_recorder_client.h"
 
6927
+#include <hybris/media/media_recorder_layer.h>
 
6928
+
 
6929
+#include <gui/IGraphicBufferProducer.h>
 
6930
+#include <media/IMediaRecorder.h>
 
6931
+#include <binder/IServiceManager.h>
 
6932
+
 
6933
+#include <utils/Log.h>
 
6934
+#include <utils/threads.h>
 
6935
+
 
6936
+#define REPORT_FUNCTION() ALOGV("%s \n", __PRETTY_FUNCTION__)
 
6937
+
 
6938
+namespace android {
 
6939
+
 
6940
+enum {
 
6941
+    CREATE_MEDIA_RECORDER = IBinder::FIRST_CALL_TRANSACTION,
 
6942
+};
 
6943
+
 
6944
+class BpMediaRecorderFactory: public BpInterface<IMediaRecorderFactory>
 
6945
+{
 
6946
+public:
 
6947
+    BpMediaRecorderFactory(const sp<IBinder>& impl)
 
6948
+        : BpInterface<IMediaRecorderFactory>(impl)
 
6949
+    {
 
6950
+    }
 
6951
+
 
6952
+    virtual sp<IMediaRecorder> createMediaRecorder()
 
6953
+    {
 
6954
+        Parcel data, reply;
 
6955
+        data.writeInterfaceToken(IMediaRecorderFactory::getInterfaceDescriptor());
 
6956
+        remote()->transact(CREATE_MEDIA_RECORDER, data, &reply);
 
6957
+        return interface_cast<IMediaRecorder>(reply.readStrongBinder());
 
6958
+    }
 
6959
+};
 
6960
+
 
6961
+// ----------------------------------------------------------------------------
 
6962
+
 
6963
+IMPLEMENT_META_INTERFACE(MediaRecorderFactory, "android.media.IMediaRecorderFactory");
 
6964
+
 
6965
+// ----------------------------------------------------------------------
 
6966
+
 
6967
+status_t BnMediaRecorderFactory::onTransact(
 
6968
+    uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags)
 
6969
+{
 
6970
+    switch (code) {
 
6971
+        case CREATE_MEDIA_RECORDER: {
 
6972
+            CHECK_INTERFACE(IMediaRecorderFactory, data, reply);
 
6973
+            sp<IMediaRecorder> recorder = createMediaRecorder();
 
6974
+            reply->writeStrongBinder(recorder->asBinder());
 
6975
+            return NO_ERROR;
 
6976
+        } break;
 
6977
+        default:
 
6978
+            return BBinder::onTransact(code, data, reply, flags);
 
6979
+    }
 
6980
+}
 
6981
+
 
6982
+// ----------------------------------------------------------------------------
 
6983
+
 
6984
+sp<MediaRecorderFactory> MediaRecorderFactory::media_recorder_factory;
 
6985
+Mutex MediaRecorderFactory::s_lock;
 
6986
+
 
6987
+MediaRecorderFactory::MediaRecorderFactory()
 
6988
+{
 
6989
+    REPORT_FUNCTION();
 
6990
+}
 
6991
+
 
6992
+MediaRecorderFactory::~MediaRecorderFactory()
 
6993
+{
 
6994
+    REPORT_FUNCTION();
 
6995
+}
 
6996
+
 
6997
+/*!
 
6998
+ * \brief Creates and adds the MediaRecorderFactory service to the default Binder ServiceManager
 
6999
+ */
 
7000
+void MediaRecorderFactory::instantiate()
 
7001
+{
 
7002
+    defaultServiceManager()->addService(
 
7003
+            String16(IMediaRecorderFactory::exported_service_name()), factory_instance());
 
7004
+    ALOGV("Added Binder service '%s' to ServiceManager", IMediaRecorderFactory::exported_service_name());
 
7005
+}
 
7006
+
 
7007
+/*!
 
7008
+ * \brief Creates a new MediaRecorderClient instance over Binder
 
7009
+ * \return A new MediaRecorderClient instance
 
7010
+ */
 
7011
+sp<IMediaRecorder> MediaRecorderFactory::createMediaRecorder()
 
7012
+{
 
7013
+    REPORT_FUNCTION();
 
7014
+    sp<MediaRecorderClient> recorder = new MediaRecorderClient();
 
7015
+    return recorder;
 
7016
+}
 
7017
+
 
7018
+/*!
 
7019
+ * \brief Get a reference to the MediaRecorderFactory singleton instance
 
7020
+ * \return The MediaRecorderFactory singleton instance
 
7021
+ */
 
7022
+sp<MediaRecorderFactory>& MediaRecorderFactory::factory_instance()
 
7023
+{
 
7024
+    REPORT_FUNCTION();
 
7025
+    Mutex::Autolock _l(s_lock);
 
7026
+    if (media_recorder_factory == NULL)
 
7027
+    {
 
7028
+        ALOGD("Creating new static instance of MediaRecorderFactory");
 
7029
+        media_recorder_factory = new MediaRecorderFactory();
 
7030
+    }
 
7031
+
 
7032
+    return media_recorder_factory;
 
7033
+}
 
7034
+
 
7035
+} // namespace android
 
7036
--- /dev/null
 
7037
+++ libhybris-0.1.0+git20131207+e452e83/compat/media/media_recorder_factory.h
 
7038
@@ -0,0 +1,72 @@
 
7039
+/*
 
7040
+ * Copyright (C) 2014 Canonical Ltd
 
7041
+ *
 
7042
+ * Licensed under the Apache License, Version 2.0 (the "License");
 
7043
+ * you may not use this file except in compliance with the License.
 
7044
+ * You may obtain a copy of the License at
 
7045
+ *
 
7046
+ *      http://www.apache.org/licenses/LICENSE-2.0
 
7047
+ *
 
7048
+ * Unless required by applicable law or agreed to in writing, software
 
7049
+ * distributed under the License is distributed on an "AS IS" BASIS,
 
7050
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 
7051
+ * See the License for the specific language governing permissions and
 
7052
+ * limitations under the License.
 
7053
+ *
 
7054
+ * Authored by: Jim Hodapp <jim.hodapp@canonical.com>
 
7055
+ */
 
7056
+
 
7057
+#ifndef MEDIA_RECORDER_FACTORY_H_
 
7058
+#define MEDIA_RECORDER_FACTORY_H_
 
7059
+
 
7060
+#include <media/IMediaRecorder.h>
 
7061
+
 
7062
+#include <binder/IInterface.h>
 
7063
+#include <binder/Parcel.h>
 
7064
+
 
7065
+namespace android {
 
7066
+
 
7067
+class Mutex;
 
7068
+
 
7069
+class IMediaRecorderFactory: public IInterface
 
7070
+{
 
7071
+public:
 
7072
+    DECLARE_META_INTERFACE(MediaRecorderFactory);
 
7073
+
 
7074
+    static const char* exported_service_name() { return "android.media.IMediaRecorderFactory"; }
 
7075
+
 
7076
+    virtual sp<IMediaRecorder> createMediaRecorder() = 0;
 
7077
+};
 
7078
+
 
7079
+// ----------------------------------------------------------------------------
 
7080
+
 
7081
+class BnMediaRecorderFactory: public BnInterface<IMediaRecorderFactory>
 
7082
+{
 
7083
+public:
 
7084
+    virtual status_t    onTransact( uint32_t code,
 
7085
+                                    const Parcel& data,
 
7086
+                                    Parcel* reply,
 
7087
+                                    uint32_t flags = 0);
 
7088
+};
 
7089
+
 
7090
+// ----------------------------------------------------------------------------
 
7091
+
 
7092
+class MediaRecorderFactory : public BnMediaRecorderFactory
 
7093
+{
 
7094
+public:
 
7095
+    MediaRecorderFactory();
 
7096
+    virtual ~MediaRecorderFactory();
 
7097
+
 
7098
+    static void instantiate();
 
7099
+
 
7100
+    virtual sp<IMediaRecorder> createMediaRecorder();
 
7101
+private:
 
7102
+    static sp<MediaRecorderFactory>& factory_instance();
 
7103
+
 
7104
+    static sp<MediaRecorderFactory> media_recorder_factory;
 
7105
+    static Mutex s_lock;
 
7106
+};
 
7107
+
 
7108
+}
 
7109
+
 
7110
+#endif
 
7111
--- /dev/null
 
7112
+++ libhybris-0.1.0+git20131207+e452e83/compat/media/media_recorder_layer.cpp
 
7113
@@ -0,0 +1,458 @@
 
7114
+/*
 
7115
+ * Copyright (C) 2013-2014 Canonical Ltd
4743
7116
+ *
4744
7117
+ * Licensed under the Apache License, Version 2.0 (the "License");
4745
7118
+ * you may not use this file except in compliance with the License.
4758
7131
+ *              Ricardo Salveti de Araujo <ricardo.salveti@canonical.com>
4759
7132
+ */
4760
7133
+
4761
 
+#include <hybris/internal/camera_control.h>
4762
 
+#include <hybris/media/recorder_compatibility_layer.h>
4763
 
+
4764
 
+#include <camera/Camera.h>
4765
 
+#include <camera/ICamera.h>
4766
 
+#include <media/mediarecorder.h>
4767
 
+
4768
 
+//#define LOG_NDEBUG 0
 
7134
+#define LOG_NDEBUG 0
4769
7135
+#undef LOG_TAG
4770
7136
+#define LOG_TAG "MediaRecorderCompatibilityLayer"
 
7137
+
 
7138
+#include "media_recorder.h"
 
7139
+
 
7140
+#include <hybris/internal/camera_control.h>
 
7141
+#include <hybris/media/media_recorder_layer.h>
 
7142
+
4771
7143
+#include <utils/KeyedVector.h>
4772
7144
+#include <utils/Log.h>
4773
7145
+
 
7146
+#include <sys/types.h>
 
7147
+#include <sys/stat.h>
 
7148
+#include <fcntl.h>
 
7149
+
4774
7150
+#define REPORT_FUNCTION() ALOGV("%s \n", __PRETTY_FUNCTION__)
4775
7151
+
 
7152
+using namespace android;
 
7153
+
4776
7154
+/*!
4777
 
+ * \brief The MediaRecorderListenerWrapper class is used to listen to events
4778
 
+ * from the MediaRecorder
 
7155
+ * \brief The MediaRecorderListenerWrapper class is used to listen to camera events
 
7156
+ * from the MediaRecorder instance
4779
7157
+ */
4780
7158
+class MediaRecorderListenerWrapper : public android::MediaRecorderListener
4781
7159
+{
4782
 
+       public:
4783
 
+               MediaRecorderListenerWrapper()
4784
 
+                       : error_cb(NULL),
4785
 
+                       error_context(NULL)
4786
 
+               {
4787
 
+               }
4788
 
+
4789
 
+               void notify(int msg, int ext1, int ext2)
4790
 
+               {
4791
 
+                       ALOGV("\tmsg: %d, ext1: %d, ext2: %d \n", msg, ext1, ext2);
4792
 
+
4793
 
+                       switch (msg) {
4794
 
+                       case android::MEDIA_RECORDER_EVENT_ERROR:
4795
 
+                               ALOGV("\tMEDIA_RECORDER_EVENT_ERROR msg\n");
4796
 
+                               // TODO: Extend this cb to include the error message
4797
 
+                               if (error_cb != NULL)
4798
 
+                                       error_cb(error_context);
4799
 
+                               else
4800
 
+                                       ALOGE("Failed to signal error to app layer, callback not set.");
4801
 
+                               break;
4802
 
+                       default:
4803
 
+                               ALOGV("\tUnknown notification\n");
4804
 
+                       }
4805
 
+               }
4806
 
+
4807
 
+               void setErrorCb(on_recorder_msg_error cb, void *context)
4808
 
+               {
4809
 
+                       REPORT_FUNCTION();
4810
 
+                       error_cb = cb;
4811
 
+                       error_context = context;
4812
 
+               }
4813
 
+
4814
 
+       private:
4815
 
+               on_recorder_msg_error error_cb;
4816
 
+               void *error_context;
 
7160
+public:
 
7161
+    MediaRecorderListenerWrapper()
 
7162
+        : error_cb(NULL),
 
7163
+          error_context(NULL)
 
7164
+{
 
7165
+}
 
7166
+
 
7167
+    void notify(int msg, int ext1, int ext2)
 
7168
+    {
 
7169
+        ALOGV("\tmsg: %d, ext1: %d, ext2: %d \n", msg, ext1, ext2);
 
7170
+
 
7171
+        switch (msg) {
 
7172
+            case android::MEDIA_RECORDER_EVENT_ERROR:
 
7173
+                ALOGV("\tMEDIA_RECORDER_EVENT_ERROR msg\n");
 
7174
+                // TODO: Extend this cb to include the error message
 
7175
+                if (error_cb != NULL)
 
7176
+                    error_cb(error_context);
 
7177
+                else
 
7178
+                    ALOGE("Failed to signal error to app layer, callback not set.");
 
7179
+                break;
 
7180
+            default:
 
7181
+                ALOGV("\tUnknown notification\n");
 
7182
+        }
 
7183
+    }
 
7184
+
 
7185
+    void setErrorCb(on_recorder_msg_error cb, void *context)
 
7186
+    {
 
7187
+        REPORT_FUNCTION();
 
7188
+        error_cb = cb;
 
7189
+        error_context = context;
 
7190
+    }
 
7191
+
 
7192
+private:
 
7193
+    on_recorder_msg_error error_cb;
 
7194
+    void *error_context;
4817
7195
+};
4818
7196
+
4819
7197
+/*!
4821
7199
+ */
4822
7200
+struct MediaRecorderWrapper : public android::MediaRecorder
4823
7201
+{
4824
 
+       public:
4825
 
+               MediaRecorderWrapper()
4826
 
+                       : MediaRecorder(),
4827
 
+                       media_recorder_listener(new MediaRecorderListenerWrapper())
4828
 
+               {
4829
 
+                       setListener(media_recorder_listener);
4830
 
+               }
4831
 
+
4832
 
+               ~MediaRecorderWrapper()
4833
 
+               {
4834
 
+                       reset();
4835
 
+               }
4836
 
+
4837
 
+               void setErrorCb(on_recorder_msg_error cb, void *context)
4838
 
+               {
4839
 
+                       REPORT_FUNCTION();
4840
 
+
4841
 
+                       assert(media_recorder_listener != NULL);
4842
 
+                       media_recorder_listener->setErrorCb(cb, context);
4843
 
+               }
4844
 
+
4845
 
+       private:
4846
 
+               android::sp<MediaRecorderListenerWrapper> media_recorder_listener;
 
7202
+public:
 
7203
+    MediaRecorderWrapper()
 
7204
+        : MediaRecorder(),
 
7205
+        media_recorder_listener(new MediaRecorderListenerWrapper())
 
7206
+{
 
7207
+    setListener(media_recorder_listener);
 
7208
+}
 
7209
+
 
7210
+    ~MediaRecorderWrapper()
 
7211
+    {
 
7212
+        reset();
 
7213
+    }
 
7214
+
 
7215
+    void setErrorCb(on_recorder_msg_error cb, void *context)
 
7216
+    {
 
7217
+        REPORT_FUNCTION();
 
7218
+
 
7219
+        assert(media_recorder_listener != NULL);
 
7220
+        media_recorder_listener->setErrorCb(cb, context);
 
7221
+    }
 
7222
+
 
7223
+private:
 
7224
+    android::sp<MediaRecorderListenerWrapper> media_recorder_listener;
4847
7225
+};
4848
7226
+
4849
 
+
4850
 
+using namespace android;
4851
 
+
4852
7227
+/*!
4853
7228
+ * \brief android_recorder_set_error_cb
4854
 
+ * \param mr A MediaRecorderWrapper instance, created by calling android_media_new_recorder()
 
7229
+ * \param mr A MediaRecorder instance, created by calling android_media_new_recorder()
4855
7230
+ * \param cb The callback function to be called when a recording error occurs
4856
 
+ * \param context
 
7231
+ * \param user context to pass through to the error handler
4857
7232
+ */
4858
7233
+void android_recorder_set_error_cb(MediaRecorderWrapper *mr, on_recorder_msg_error cb,
4859
 
+               void *context)
 
7234
+        void *context)
4860
7235
+{
4861
 
+       REPORT_FUNCTION();
4862
 
+
4863
 
+       if (mr == NULL) {
4864
 
+               ALOGE("mr must not be NULL");
4865
 
+               return;
4866
 
+       }
4867
 
+
4868
 
+       mr->setErrorCb(cb, context);
 
7236
+    REPORT_FUNCTION();
 
7237
+
 
7238
+    if (mr == NULL) {
 
7239
+        ALOGE("mr must not be NULL");
 
7240
+        return;
 
7241
+    }
 
7242
+
 
7243
+    mr->setErrorCb(cb, context);
4869
7244
+}
4870
7245
+
4871
7246
+/*!
4874
7249
+ */
4875
7250
+MediaRecorderWrapper *android_media_new_recorder()
4876
7251
+{
4877
 
+       REPORT_FUNCTION();
4878
 
+
4879
 
+       MediaRecorderWrapper *mr = new MediaRecorderWrapper;
4880
 
+       if (mr == NULL) {
4881
 
+               ALOGE("Failed to create new MediaRecorderWrapper instance.");
4882
 
+               return NULL;
4883
 
+       }
4884
 
+
4885
 
+       return mr;
 
7252
+    REPORT_FUNCTION();
 
7253
+
 
7254
+    MediaRecorderWrapper *mr = new MediaRecorderWrapper;
 
7255
+    if (mr == NULL) {
 
7256
+        ALOGE("Failed to create new MediaRecorder instance.");
 
7257
+        return NULL;
 
7258
+    }
 
7259
+
 
7260
+    return mr;
4886
7261
+}
4887
7262
+
4888
7263
+/*!
4889
7264
+ * \brief android_recorder_initCheck
4890
 
+ * \param mr A MediaRecorderWrapper instance, created by calling android_media_new_recorder()
 
7265
+ * \param mr A MediaRecorder instance, created by calling android_media_new_recorder()
4891
7266
+ * \return negative value if an error occured
4892
7267
+ */
4893
7268
+int android_recorder_initCheck(MediaRecorderWrapper *mr)
4894
7269
+{
4895
 
+       REPORT_FUNCTION();
4896
 
+
4897
 
+       if (mr == NULL) {
4898
 
+               ALOGE("mr must not be NULL");
4899
 
+               return BAD_VALUE;
4900
 
+       }
4901
 
+
4902
 
+       return mr->initCheck();
 
7270
+    REPORT_FUNCTION();
 
7271
+
 
7272
+    if (mr == NULL) {
 
7273
+        ALOGE("mr must not be NULL");
 
7274
+        return android::BAD_VALUE;
 
7275
+    }
 
7276
+
 
7277
+    return mr->initCheck();
4903
7278
+}
4904
7279
+
4905
7280
+/*!
4906
 
+ * \brief android_recorder_setCamera sets the camera object for recording videos
4907
 
+ * from the camera
4908
 
+ * \param mr A MediaRecorderWrapper instance, created by calling android_media_new_recorder()
 
7281
+ * \brief android_recorder_setCamera sets the camera object for recording videos from the camera
 
7282
+ * \param mr A MediaRecorder instance, created by calling android_media_new_recorder()
4909
7283
+ * \param control Wrapper for the camera (see camera in hybris)
4910
7284
+ * \return negative value if an error occured
4911
7285
+ */
4912
7286
+int android_recorder_setCamera(MediaRecorderWrapper *mr, CameraControl* control)
4913
7287
+{
4914
 
+       REPORT_FUNCTION();
4915
 
+
4916
 
+       if (mr == NULL) {
4917
 
+               ALOGE("mr must not be NULL");
4918
 
+               return BAD_VALUE;
4919
 
+       }
4920
 
+       if (control == NULL) {
4921
 
+               ALOGE("control must not be NULL");
4922
 
+               return BAD_VALUE;
4923
 
+       }
4924
 
+
4925
 
+       return mr->setCamera(control->camera->remote(), control->camera->getRecordingProxy());
 
7288
+    REPORT_FUNCTION();
 
7289
+
 
7290
+    if (mr == NULL) {
 
7291
+        ALOGE("mr must not be NULL");
 
7292
+        return android::BAD_VALUE;
 
7293
+    }
 
7294
+    if (control == NULL) {
 
7295
+        ALOGE("control must not be NULL");
 
7296
+        return android::BAD_VALUE;
 
7297
+    }
 
7298
+
 
7299
+    return mr->setCamera(control->camera->remote(), control->camera->getRecordingProxy());
4926
7300
+}
4927
7301
+
4928
7302
+/*!
4929
7303
+ * \brief android_recorder_setVideoSource sets the video source.
4930
7304
+ * If no video source is set, only audio is recorded.
4931
 
+ * \param mr A MediaRecorderWrapper instance, created by calling android_media_new_recorder()
4932
 
+ * \param vs The video source. It's either the camera of gralloc buffer
 
7305
+ * \param mr A MediaRecorder instance, created by calling android_media_new_recorder()
 
7306
+ * \param vs The video source. It's either a camera or a gralloc buffer
4933
7307
+ * \return negative value if an error occured
4934
7308
+ */
4935
7309
+int android_recorder_setVideoSource(MediaRecorderWrapper *mr, VideoSource vs)
4936
7310
+{
4937
 
+       REPORT_FUNCTION();
4938
 
+
4939
 
+       if (mr == NULL) {
4940
 
+               ALOGE("mr must not be NULL");
4941
 
+               return BAD_VALUE;
4942
 
+       }
4943
 
+
4944
 
+       return mr->setVideoSource(static_cast<int>(vs));
 
7311
+    REPORT_FUNCTION();
 
7312
+
 
7313
+    if (mr == NULL) {
 
7314
+        ALOGE("mr must not be NULL");
 
7315
+        return android::BAD_VALUE;
 
7316
+    }
 
7317
+
 
7318
+    return mr->setVideoSource(static_cast<int>(vs));
4945
7319
+}
4946
7320
+
4947
7321
+/*!
4948
7322
+ * \brief android_recorder_setAudioSource
4949
 
+ * \param mr A MediaRecorderWrapper instance, created by calling android_media_new_recorder()
 
7323
+ * \param mr A MediaRecorder instance, created by calling android_media_new_recorder()
4950
7324
+ * \param as The audio source.
4951
7325
+ * \return negative value if an error occured
4952
7326
+ */
4953
7327
+int android_recorder_setAudioSource(MediaRecorderWrapper *mr, AudioSource as)
4954
7328
+{
4955
 
+       REPORT_FUNCTION();
4956
 
+
4957
 
+       if (mr == NULL) {
4958
 
+               ALOGE("mr must not be NULL");
4959
 
+               return BAD_VALUE;
4960
 
+       }
4961
 
+
4962
 
+       return mr->setAudioSource(static_cast<int>(as));
 
7329
+    REPORT_FUNCTION();
 
7330
+
 
7331
+    if (mr == NULL) {
 
7332
+        ALOGE("mr must not be NULL");
 
7333
+        return android::BAD_VALUE;
 
7334
+    }
 
7335
+
 
7336
+    return mr->setAudioSource(static_cast<int>(as));
4963
7337
+}
4964
7338
+
4965
7339
+/*!
4966
7340
+ * \brief android_recorder_setOutputFormat
4967
 
+ * \param mr A MediaRecorderWrapper instance, created by calling android_media_new_recorder()
4968
 
+ * \param of The output file format
 
7341
+ * \param mr A MediaRecorder instance, created by calling android_media_new_recorder()
 
7342
+ * \param of The output file container format
4969
7343
+ * \return negative value if an error occured
4970
7344
+ */
4971
7345
+int android_recorder_setOutputFormat(MediaRecorderWrapper *mr, OutputFormat of)
4972
7346
+{
4973
 
+       REPORT_FUNCTION();
4974
 
+
4975
 
+       if (mr == NULL) {
4976
 
+               ALOGE("mr must not be NULL");
4977
 
+               return BAD_VALUE;
4978
 
+       }
4979
 
+
4980
 
+       return mr->setOutputFormat(static_cast<int>(of));
 
7347
+    REPORT_FUNCTION();
 
7348
+
 
7349
+    if (mr == NULL) {
 
7350
+        ALOGE("mr must not be NULL");
 
7351
+        return android::BAD_VALUE;
 
7352
+    }
 
7353
+
 
7354
+    return mr->setOutputFormat(static_cast<int>(of));
4981
7355
+}
4982
7356
+
4983
7357
+/*!
4984
7358
+ * \brief android_recorder_setVideoEncoder
4985
 
+ * \param mr A MediaRecorderWrapper instance, created by calling android_media_new_recorder()
4986
 
+ * \param ve The video encoder sets the codec for the video
 
7359
+ * \param mr A MediaRecorder instance, created by calling android_media_new_recorder()
 
7360
+ * \param ve The video encoder sets the codec type for encoding/recording video
4987
7361
+ * \return negative value if an error occured
4988
7362
+ */
4989
7363
+int android_recorder_setVideoEncoder(MediaRecorderWrapper *mr, VideoEncoder ve)
4990
7364
+{
4991
 
+       REPORT_FUNCTION();
4992
 
+
4993
 
+       if (mr == NULL) {
4994
 
+               ALOGE("mr must not be NULL");
4995
 
+               return BAD_VALUE;
4996
 
+       }
4997
 
+
4998
 
+       return mr->setVideoEncoder(static_cast<int>(ve));
 
7365
+    REPORT_FUNCTION();
 
7366
+
 
7367
+    if (mr == NULL) {
 
7368
+        ALOGE("mr must not be NULL");
 
7369
+        return android::BAD_VALUE;
 
7370
+    }
 
7371
+
 
7372
+    return mr->setVideoEncoder(static_cast<int>(ve));
4999
7373
+}
5000
7374
+
5001
7375
+/*!
5002
7376
+ * \brief android_recorder_setAudioEncoder
5003
 
+ * \param mr A MediaRecorderWrapper instance, created by calling android_media_new_recorder()
5004
 
+ * \param ae The audio encoder sets the codec for the audio
 
7377
+ * \param mr A MediaRecorder instance, created by calling android_media_new_recorder()
 
7378
+ * \param ae The audio encoder sets the codec type for encoding/recording audio
5005
7379
+ * \return negative value if an error occured
5006
7380
+ */
5007
7381
+int android_recorder_setAudioEncoder(MediaRecorderWrapper *mr, AudioEncoder ae)
5008
7382
+{
5009
 
+       REPORT_FUNCTION();
5010
 
+
5011
 
+       if (mr == NULL) {
5012
 
+               ALOGE("mr must not be NULL");
5013
 
+               return BAD_VALUE;
5014
 
+       }
5015
 
+
5016
 
+       return mr->setAudioEncoder(static_cast<int>(ae));
 
7383
+    REPORT_FUNCTION();
 
7384
+
 
7385
+    if (mr == NULL) {
 
7386
+        ALOGE("mr must not be NULL");
 
7387
+        return android::BAD_VALUE;
 
7388
+    }
 
7389
+
 
7390
+    return mr->setAudioEncoder(static_cast<int>(ae));
5017
7391
+}
5018
7392
+
5019
7393
+/*!
5020
7394
+ * \brief android_recorder_setOutputFile sets the output file to the given file descriptor
5021
 
+ * \param mr A MediaRecorderWrapper instance, created by calling android_media_new_recorder()
 
7395
+ * \param mr A MediaRecorder instance, created by calling android_media_new_recorder()
5022
7396
+ * \param fd File descriptor of an open file, that the stream can be written to
5023
7397
+ * \return negative value if an error occured
5024
7398
+ */
5025
7399
+int android_recorder_setOutputFile(MediaRecorderWrapper *mr, int fd)
5026
7400
+{
5027
 
+       REPORT_FUNCTION();
5028
 
+
5029
 
+       if (mr == NULL) {
5030
 
+               ALOGE("mr must not be NULL");
5031
 
+               return BAD_VALUE;
5032
 
+       }
5033
 
+
5034
 
+       return mr->setOutputFile(fd, 0, 0);
 
7401
+    REPORT_FUNCTION();
 
7402
+
 
7403
+    if (mr == NULL) {
 
7404
+        ALOGE("mr must not be NULL");
 
7405
+        return android::BAD_VALUE;
 
7406
+    }
 
7407
+
 
7408
+    return mr->setOutputFile(fd, 0, 0);
5035
7409
+}
5036
7410
+
5037
7411
+/*!
5038
7412
+ * \brief android_recorder_setVideoSize
5039
 
+ * \param mr A MediaRecorderWrapper instance, created by calling android_media_new_recorder()
5040
 
+ * \param width width for the video to record
5041
 
+ * \param height height for the video to record
 
7413
+ * \param mr A MediaRecorder instance, created by calling android_media_new_recorder()
 
7414
+ * \param width output width for the video to record
 
7415
+ * \param height output height for the video to record
5042
7416
+ * \return negative value if an error occured
5043
7417
+ */
5044
7418
+int android_recorder_setVideoSize(MediaRecorderWrapper *mr, int width, int height)
5045
7419
+{
5046
 
+       REPORT_FUNCTION();
5047
 
+
5048
 
+       if (mr == NULL) {
5049
 
+               ALOGE("mr must not be NULL");
5050
 
+               return BAD_VALUE;
5051
 
+       }
5052
 
+
5053
 
+       return mr->setVideoSize(width, height);
 
7420
+    REPORT_FUNCTION();
 
7421
+
 
7422
+    if (mr == NULL) {
 
7423
+        ALOGE("mr must not be NULL");
 
7424
+        return android::BAD_VALUE;
 
7425
+    }
 
7426
+
 
7427
+    return mr->setVideoSize(width, height);
5054
7428
+}
5055
7429
+
5056
7430
+/*!
5057
7431
+ * \brief android_recorder_setVideoFrameRate
5058
 
+ * \param mr A MediaRecorderWrapper instance, created by calling android_media_new_recorder()
5059
 
+ * \param frames_per_second Frames per second has typical values for a movie clip in 720p is 30
 
7432
+ * \param mr A MediaRecorder instance, created by calling android_media_new_recorder()
 
7433
+ * \param frames_per_second How many frames per second to record at (e.g. 720p is typically 30)
5060
7434
+ * \return negative value if an error occured
5061
7435
+ */
5062
7436
+int android_recorder_setVideoFrameRate(MediaRecorderWrapper *mr, int frames_per_second)
5063
7437
+{
5064
 
+       REPORT_FUNCTION();
5065
 
+
5066
 
+       if (mr == NULL) {
5067
 
+               ALOGE("mr must not be NULL");
5068
 
+               return BAD_VALUE;
5069
 
+       }
5070
 
+
5071
 
+       return mr->setVideoFrameRate(frames_per_second);
 
7438
+    REPORT_FUNCTION();
 
7439
+
 
7440
+    if (mr == NULL) {
 
7441
+        ALOGE("mr must not be NULL");
 
7442
+        return android::BAD_VALUE;
 
7443
+    }
 
7444
+
 
7445
+    return mr->setVideoFrameRate(frames_per_second);
5072
7446
+}
5073
7447
+
5074
7448
+/*!
5075
7449
+ * \brief android_recorder_setParameters sets a parameter. Even those without
5076
7450
+ * explicit function.
5077
 
+ * For possible parameters look for example in StagefrightRecorder::setParameter()
5078
 
+ * \param mr A MediaRecorderWrapper instance, created by calling android_media_new_recorder()
 
7451
+ * For possible parameter pairs look for examples in StagefrightRecorder::setParameter()
 
7452
+ * \param mr A MediaRecorder instance, created by calling android_media_new_recorder()
5079
7453
+ * \param parameters list of parameters. format is "parameter1=value;parameter2=value"
5080
7454
+ * \return negative value if an error occured
5081
7455
+ */
5082
 
+int android_recorder_setParameters(MediaRecorderWrapper *mr, const char* parameters)
 
7456
+int android_recorder_setParameters(MediaRecorderWrapper *mr, const char *parameters)
5083
7457
+{
5084
 
+       REPORT_FUNCTION();
5085
 
+
5086
 
+       if (mr == NULL) {
5087
 
+               ALOGE("mr must not be NULL");
5088
 
+               return BAD_VALUE;
5089
 
+       }
5090
 
+
5091
 
+       String8 params(parameters);
5092
 
+       return mr->setParameters(params);
 
7458
+    REPORT_FUNCTION();
 
7459
+
 
7460
+    if (mr == NULL) {
 
7461
+        ALOGE("mr must not be NULL");
 
7462
+        return android::BAD_VALUE;
 
7463
+    }
 
7464
+
 
7465
+    android::String8 params(parameters);
 
7466
+    return mr->setParameters(params);
5093
7467
+}
5094
7468
+
5095
7469
+/*!
5096
7470
+ * \brief android_recorder_start starts the recording.
5097
 
+ * The MediaRecorder has to be in state "prepared"
5098
 
+ * \param mr A MediaRecorderWrapper instance, created by calling android_media_new_recorder()
 
7471
+ * The MediaRecorder has to be in state "prepared" (call android_recorder_prepare() first)
 
7472
+ * \param mr A MediaRecorder instance, created by calling android_media_new_recorder()
5099
7473
+ * \return negative value if an error occured
5100
7474
+ */
5101
7475
+int android_recorder_start(MediaRecorderWrapper *mr)
5102
7476
+{
5103
 
+       REPORT_FUNCTION();
5104
 
+
5105
 
+       if (mr == NULL) {
5106
 
+               ALOGE("mr must not be NULL");
5107
 
+               return BAD_VALUE;
5108
 
+       }
5109
 
+
5110
 
+       return mr->start();
 
7477
+    REPORT_FUNCTION();
 
7478
+
 
7479
+    if (mr == NULL) {
 
7480
+        ALOGE("mr must not be NULL");
 
7481
+        return android::BAD_VALUE;
 
7482
+    }
 
7483
+
 
7484
+    return mr->start();
5111
7485
+}
5112
7486
+
5113
7487
+/*!
5114
7488
+ * \brief android_recorder_stop Stops a running recording.
5115
 
+ * \param mr A MediaRecorderWrapper instance, created by calling android_media_new_recorder()
 
7489
+ * \param mr A MediaRecorder instance, created by calling android_media_new_recorder()
5116
7490
+ * \return negative value if an error occured
5117
7491
+ */
5118
7492
+int android_recorder_stop(MediaRecorderWrapper *mr)
5119
7493
+{
5120
 
+       REPORT_FUNCTION();
5121
 
+
5122
 
+       if (mr == NULL) {
5123
 
+               ALOGE("mr must not be NULL");
5124
 
+               return BAD_VALUE;
5125
 
+       }
5126
 
+
5127
 
+       return mr->stop();
 
7494
+    REPORT_FUNCTION();
 
7495
+
 
7496
+    if (mr == NULL) {
 
7497
+        ALOGE("mr must not be NULL");
 
7498
+        return android::BAD_VALUE;
 
7499
+    }
 
7500
+
 
7501
+    return mr->stop();
5128
7502
+}
5129
7503
+
5130
7504
+/*!
5131
7505
+ * \brief android_recorder_prepare put the MediaRecorder into state "prepare"
5132
 
+ * \param mr A MediaRecorderWrapper instance, created by calling android_media_new_recorder()
 
7506
+ * \param mr A MediaRecorder instance, created by calling android_media_new_recorder()
5133
7507
+ * \return negative value if an error occured
5134
7508
+ */
5135
7509
+int android_recorder_prepare(MediaRecorderWrapper *mr)
5136
7510
+{
5137
 
+       REPORT_FUNCTION();
5138
 
+
5139
 
+       if (mr == NULL) {
5140
 
+               ALOGE("mr must not be NULL");
5141
 
+               return BAD_VALUE;
5142
 
+       }
5143
 
+
5144
 
+       return mr->prepare();
 
7511
+    REPORT_FUNCTION();
 
7512
+
 
7513
+    if (mr == NULL) {
 
7514
+        ALOGE("mr must not be NULL");
 
7515
+        return android::BAD_VALUE;
 
7516
+    }
 
7517
+
 
7518
+    return mr->prepare();
5145
7519
+}
5146
7520
+
5147
7521
+/*!
5148
7522
+ * \brief android_recorder_reset resets the MediaRecorder
5149
 
+ * \param mr A MediaRecorderWrapper instance, created by calling android_media_new_recorder()
 
7523
+ * \param mr A MediaRecorder instance, created by calling android_media_new_recorder()
5150
7524
+ * \return negative value if an error occured
5151
7525
+ */
5152
7526
+int android_recorder_reset(MediaRecorderWrapper *mr)
5153
7527
+{
5154
 
+       REPORT_FUNCTION();
5155
 
+
5156
 
+       if (mr == NULL) {
5157
 
+               ALOGE("mr must not be NULL");
5158
 
+               return BAD_VALUE;
5159
 
+       }
5160
 
+
5161
 
+       return mr->reset();
 
7528
+    REPORT_FUNCTION();
 
7529
+
 
7530
+    if (mr == NULL) {
 
7531
+        ALOGE("mr must not be NULL");
 
7532
+        return android::BAD_VALUE;
 
7533
+    }
 
7534
+
 
7535
+    return mr->reset();
5162
7536
+}
5163
7537
+
5164
7538
+/*!
5165
7539
+ * \brief android_recorder_close closes the MediaRecorder
5166
 
+ * \param mr A MediaRecorderWrapper instance, created by calling android_media_new_recorder()
 
7540
+ * \param mr A MediaRecorder instance, created by calling android_media_new_recorder()
5167
7541
+ * \return negative value if an error occured
5168
7542
+ */
5169
7543
+int android_recorder_close(MediaRecorderWrapper *mr)
5170
7544
+{
5171
 
+       REPORT_FUNCTION();
5172
 
+
5173
 
+       if (mr == NULL) {
5174
 
+               ALOGE("mr must not be NULL");
5175
 
+               return BAD_VALUE;
5176
 
+       }
5177
 
+
5178
 
+       return mr->close();
 
7545
+    REPORT_FUNCTION();
 
7546
+
 
7547
+    if (mr == NULL) {
 
7548
+        ALOGE("mr must not be NULL");
 
7549
+        return android::BAD_VALUE;
 
7550
+    }
 
7551
+
 
7552
+    return mr->close();
5179
7553
+}
5180
7554
+
5181
7555
+/*!
5182
7556
+ * \brief android_recorder_release releases the MediaRecorder resources
5183
 
+ * This deletes the object. So don't use it after calling this function.
5184
 
+ * \param mr A MediaRecorderWrapper instance, created by calling android_media_new_recorder()
 
7557
+ * This deletes the MediaRecorder instance. So don't use the instance after calling this function.
 
7558
+ * \param mr A MediaRecorder instance, created by calling android_media_new_recorder()
5185
7559
+ * \return negative value if an error occured
5186
7560
+ */
5187
7561
+int android_recorder_release(MediaRecorderWrapper *mr)
5188
7562
+{
5189
 
+       REPORT_FUNCTION();
5190
 
+
5191
 
+       if (mr == NULL) {
5192
 
+               ALOGE("mr must not be NULL");
5193
 
+               return BAD_VALUE;
5194
 
+       }
5195
 
+
5196
 
+       return mr->release();
 
7563
+    REPORT_FUNCTION();
 
7564
+
 
7565
+    if (mr == NULL) {
 
7566
+        ALOGE("mr must not be NULL");
 
7567
+        return android::BAD_VALUE;
 
7568
+    }
 
7569
+
 
7570
+    return mr->release();
5197
7571
+}
5198
7572
--- /dev/null
5199
7573
+++ libhybris-0.1.0+git20131207+e452e83/compat/media/surface_texture_client_hybris.cpp
6634
9008
 }
6635
9009
--- libhybris-0.1.0+git20131207+e452e83.orig/hybris/include/Makefile.am
6636
9010
+++ libhybris-0.1.0+git20131207+e452e83/hybris/include/Makefile.am
6637
 
@@ -65,6 +65,15 @@ propertiesincludedir = $(includedir)/hyb
 
9011
@@ -65,6 +65,16 @@ propertiesincludedir = $(includedir)/hyb
6638
9012
 propertiesinclude_HEADERS = \
6639
9013
        hybris/properties/properties.h
6640
9014
 
6644
9018
+       hybris/media/media_codec_layer.h \
6645
9019
+       hybris/media/media_codec_list.h \
6646
9020
+       hybris/media/media_format_layer.h \
 
9021
+       hybris/media/media_recorder_layer.h \
6647
9022
+       hybris/media/surface_texture_client_hybris.h \
6648
9023
+       hybris/media/recorder_compatibility_layer.h
6649
9024
+
7055
9430
+
7056
9431
+#endif // MEDIA_FORMAT_LAYER_H_
7057
9432
--- /dev/null
 
9433
+++ libhybris-0.1.0+git20131207+e452e83/hybris/include/hybris/media/media_recorder_layer.h
 
9434
@@ -0,0 +1,126 @@
 
9435
+/*
 
9436
+ * Copyright (C) 2013-2014 Canonical Ltd
 
9437
+ *
 
9438
+ * Licensed under the Apache License, Version 2.0 (the "License");
 
9439
+ * you may not use this file except in compliance with the License.
 
9440
+ * You may obtain a copy of the License at
 
9441
+ *
 
9442
+ *      http://www.apache.org/licenses/LICENSE-2.0
 
9443
+ *
 
9444
+ * Unless required by applicable law or agreed to in writing, software
 
9445
+ * distributed under the License is distributed on an "AS IS" BASIS,
 
9446
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 
9447
+ * See the License for the specific language governing permissions and
 
9448
+ * limitations under the License.
 
9449
+ */
 
9450
+
 
9451
+#ifndef MEDIA_RECORDER_LAYER_H_
 
9452
+#define MEDIA_RECORDER_LAYER_H_
 
9453
+
 
9454
+#include <stdint.h>
 
9455
+#include <unistd.h>
 
9456
+#include <stdint.h>
 
9457
+#include <stdbool.h>
 
9458
+
 
9459
+#ifdef __cplusplus
 
9460
+extern "C" {
 
9461
+#endif
 
9462
+
 
9463
+    struct MediaRecorderWrapper;
 
9464
+    struct CameraControl;
 
9465
+
 
9466
+    // Values are from andoid /frameworks/av/include/media/mediarecorder.h
 
9467
+    typedef enum
 
9468
+    {
 
9469
+        ANDROID_VIDEO_SOURCE_DEFAULT = 0,
 
9470
+        ANDROID_VIDEO_SOURCE_CAMERA = 1,
 
9471
+        ANDROID_VIDEO_SOURCE_GRALLOC_BUFFER = 2
 
9472
+    } VideoSource;
 
9473
+
 
9474
+    // Values are from andoid /system/core/include/system/audio.h
 
9475
+    typedef enum
 
9476
+    {
 
9477
+        ANDROID_AUDIO_SOURCE_DEFAULT             = 0,
 
9478
+        ANDROID_AUDIO_SOURCE_MIC                 = 1,
 
9479
+        ANDROID_AUDIO_SOURCE_VOICE_UPLINK        = 2,
 
9480
+        ANDROID_AUDIO_SOURCE_VOICE_DOWNLINK      = 3,
 
9481
+        ANDROID_AUDIO_SOURCE_VOICE_CALL          = 4,
 
9482
+        ANDROID_AUDIO_SOURCE_CAMCORDER           = 5,
 
9483
+        ANDROID_AUDIO_SOURCE_VOICE_RECOGNITION   = 6,
 
9484
+        ANDROID_AUDIO_SOURCE_VOICE_COMMUNICATION = 7,
 
9485
+        ANDROID_AUDIO_SOURCE_REMOTE_SUBMIX       = 8,
 
9486
+        ANDROID_AUDIO_SOURCE_CNT,
 
9487
+        ANDROID_AUDIO_SOURCE_MAX                 = ANDROID_AUDIO_SOURCE_CNT - 1
 
9488
+    } AudioSource;
 
9489
+
 
9490
+    // Values are from andoid /frameworks/av/include/media/mediarecorder.h
 
9491
+    typedef enum
 
9492
+    {
 
9493
+        ANDROID_OUTPUT_FORMAT_DEFAULT = 0,
 
9494
+        ANDROID_OUTPUT_FORMAT_THREE_GPP = 1,
 
9495
+        ANDROID_OUTPUT_FORMAT_MPEG_4 = 2,
 
9496
+        ANDROID_OUTPUT_FORMAT_AUDIO_ONLY_START = 3,
 
9497
+        /* These are audio only file formats */
 
9498
+        ANDROID_OUTPUT_FORMAT_RAW_AMR = 3, // to be backward compatible
 
9499
+        ANDROID_OUTPUT_FORMAT_AMR_NB = 3,
 
9500
+        ANDROID_OUTPUT_FORMAT_AMR_WB = 4,
 
9501
+        ANDROID_OUTPUT_FORMAT_AAC_ADIF = 5,
 
9502
+        ANDROID_OUTPUT_FORMAT_AAC_ADTS = 6,
 
9503
+        /* Stream over a socket, limited to a single stream */
 
9504
+        ANDROID_OUTPUT_FORMAT_RTP_AVP = 7,
 
9505
+        /* H.264/AAC data encapsulated in MPEG2/TS */
 
9506
+        ANDROID_OUTPUT_FORMAT_MPEG2TS = 8
 
9507
+    } OutputFormat;
 
9508
+
 
9509
+    // Values are from andoid /frameworks/av/include/media/mediarecorder.h
 
9510
+    typedef enum
 
9511
+    {
 
9512
+        ANDROID_VIDEO_ENCODER_DEFAULT = 0,
 
9513
+        ANDROID_VIDEO_ENCODER_H263 = 1,
 
9514
+        ANDROID_VIDEO_ENCODER_H264 = 2,
 
9515
+        ANDROID_VIDEO_ENCODER_MPEG_4_SP = 3
 
9516
+    } VideoEncoder;
 
9517
+
 
9518
+    // Values are from andoid /frameworks/av/include/media/mediarecorder.h
 
9519
+    typedef enum
 
9520
+    {
 
9521
+        ANDROID_AUDIO_ENCODER_DEFAULT = 0,
 
9522
+        ANDROID_AUDIO_ENCODER_AMR_NB = 1,
 
9523
+        ANDROID_AUDIO_ENCODER_AMR_WB = 2,
 
9524
+        ANDROID_AUDIO_ENCODER_AAC = 3,
 
9525
+        ANDROID_AUDIO_ENCODER_HE_AAC = 4,
 
9526
+        ANDROID_AUDIO_ENCODER_AAC_ELD = 5
 
9527
+    } AudioEncoder;
 
9528
+
 
9529
+    // Callback types
 
9530
+    typedef void (*on_recorder_msg_error)(void *context);
 
9531
+
 
9532
+    // Callback setters
 
9533
+    void android_recorder_set_error_cb(struct MediaRecorderWrapper *mr, on_recorder_msg_error cb,
 
9534
+                                       void *context);
 
9535
+
 
9536
+    // Main recorder control API
 
9537
+    struct MediaRecorderWrapper *android_media_new_recorder();
 
9538
+    int android_recorder_initCheck(struct MediaRecorderWrapper *mr);
 
9539
+    int android_recorder_setCamera(struct MediaRecorderWrapper *mr, struct CameraControl* control);
 
9540
+    int android_recorder_setVideoSource(struct MediaRecorderWrapper *mr, VideoSource vs);
 
9541
+    int android_recorder_setAudioSource(struct MediaRecorderWrapper *mr, AudioSource as);
 
9542
+    int android_recorder_setOutputFormat(struct MediaRecorderWrapper *mr, OutputFormat of);
 
9543
+    int android_recorder_setVideoEncoder(struct MediaRecorderWrapper *mr, VideoEncoder ve);
 
9544
+    int android_recorder_setAudioEncoder(struct MediaRecorderWrapper *mr, AudioEncoder ae);
 
9545
+    int android_recorder_setOutputFile(struct MediaRecorderWrapper *mr, int fd);
 
9546
+    int android_recorder_setVideoSize(struct MediaRecorderWrapper *mr, int width, int height);
 
9547
+    int android_recorder_setVideoFrameRate(struct MediaRecorderWrapper *mr, int frames_per_second);
 
9548
+    int android_recorder_setParameters(struct MediaRecorderWrapper *mr, const char* parameters);
 
9549
+    int android_recorder_start(struct MediaRecorderWrapper *mr);
 
9550
+    int android_recorder_stop(struct MediaRecorderWrapper *mr);
 
9551
+    int android_recorder_prepare(struct MediaRecorderWrapper *mr);
 
9552
+    int android_recorder_reset(struct MediaRecorderWrapper *mr);
 
9553
+    int android_recorder_close(struct MediaRecorderWrapper *mr);
 
9554
+    int android_recorder_release(struct MediaRecorderWrapper *mr);
 
9555
+
 
9556
+#ifdef __cplusplus
 
9557
+}
 
9558
+#endif
 
9559
+
 
9560
+#endif
 
9561
--- /dev/null
7058
9562
+++ libhybris-0.1.0+git20131207+e452e83/hybris/include/hybris/media/recorder_compatibility_layer.h
7059
9563
@@ -0,0 +1,126 @@
7060
9564
+/*