138
155
void android_camera_start_preview(CameraControl* control)
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
161
- * Copyright (C) 2013 Canonical Ltd
162
+ * Copyright (C) 2013-2014 Canonical Ltd
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
168
- * http://www.apache.org/licenses/LICENSE-2.0
169
+ * http://www.apache.org/licenses/LICENSE-2.0
171
* Unless required by applicable law or agreed to in writing, software
172
* distributed under the License is distributed on an "AS IS" BASIS,
174
* limitations under the License.
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>
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>
186
#include <hybris/input/input_stack_compatibility_layer.h>
187
#include <hybris/input/input_stack_compatibility_layer_codes_key.h>
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;
197
EffectMode next_effect()
199
@@ -122,7 +128,7 @@ void jpeg_data_cb(void* data, uint32_t d
200
printf("%s: %d \n", __PRETTY_FUNCTION__, data_size);
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);
208
@@ -135,131 +141,43 @@ void jpeg_data_cb(void* data, uint32_t d
209
void size_cb(void* ctx, int width, int height)
211
printf("Supported size: [%d,%d]\n", width, height);
214
-void preview_texture_needs_update_cb(void* ctx)
216
- new_camera_frame_available = true;
219
-void on_new_input_event(Event* event, void* context)
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);
226
- CameraControl* cc = static_cast<CameraControl*>(context);
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);
233
- case ISCL_KEYCODE_VOLUME_DOWN:
234
- printf("\tZooming out now.\n");
235
- android_camera_start_zoom(cc, current_zoom_level-1);
237
- case ISCL_KEYCODE_POWER:
238
- printf("\tTaking a photo now.\n");
239
- android_camera_take_snapshot(cc);
241
- case ISCL_KEYCODE_HEADSETHOOK:
242
- printf("\tSwitching effect.\n");
243
- android_camera_set_effect_mode(cc, next_effect());
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);
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);
261
-struct ClientWithSurface
264
- SfSurface* surface;
267
-ClientWithSurface client_with_surface(bool setup_surface_with_egl)
269
- ClientWithSurface cs = ClientWithSurface();
271
- cs.client = sf_client_create();
274
- printf("Problem creating client ... aborting now.");
278
- static const size_t primary_display = 0;
280
- SfSurfaceCreationParameters params = {
283
- (int) sf_get_display_width(primary_display),
284
- (int) sf_get_display_height(primary_display),
285
- -1, //PIXEL_FORMAT_RGBA_8888,
288
- setup_surface_with_egl, // Do not associate surface with egl, will be done by camera HAL
289
- "CameraCompatLayerTestSurface"
292
- cs.surface = sf_surface_create(cs.client, ¶ms);
295
- printf("Problem creating surface ... aborting now.");
297
+ if (width == 1024 && height == 768) {
298
+ camera_width = 1024;
299
+ camera_height = 768;
302
- sf_surface_make_current(cs.surface);
307
-#define PRINT_GLERROR() printf("GL error@%d: %x\n", __LINE__, glGetError());
311
static const char* vertex_shader()
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"
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"
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"
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"
342
static const char* fragment_shader()
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"
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"
357
" gl_FragColor = texture2D( s_texture, v_texCoord );\n"
362
static GLuint loadShader(GLenum shaderType, const char* pSource)
363
@@ -354,6 +272,254 @@ struct RenderData
368
+static RenderData render_data;
369
+static EGLDisplay disp;
370
+static EGLSurface surface;
372
+void preview_texture_needs_update_cb(void* ctx)
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
386
+ GLushort indices[] = { 0, 1, 2, 0, 2, 3 };
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,
401
+ 5 * sizeof(GLfloat),
403
+ // Load the texture coordinate
404
+ glVertexAttribPointer(render_data.tex_coord_loc,
408
+ 5 * sizeof(GLfloat),
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);
422
+ eglSwapBuffers(disp, surface);
425
+static void errorCB(void *context)
427
+ ALOGE("Error while recording.");
430
+static MediaRecorderWrapper *start_video_recording(CameraControl *camera_control)
433
+ struct MediaRecorderWrapper *recorder = android_media_new_recorder();
434
+ android_recorder_set_error_cb(recorder, &errorCB, NULL);
436
+ ALOGD("Unlocking camera");
437
+ android_camera_unlock(camera_control);
438
+ if (recorder == NULL)
439
+ ALOGW("recorder is NULL: %d", __LINE__);
441
+ ret = android_recorder_setCamera(recorder, camera_control);
443
+ ALOGE("android_recorder_setCamera() failed");
446
+ ret = android_recorder_setAudioSource(recorder, ANDROID_AUDIO_SOURCE_CAMCORDER);
448
+ ALOGE("android_recorder_setAudioSource() failed");
451
+ ret = android_recorder_setVideoSource(recorder, ANDROID_VIDEO_SOURCE_CAMERA);
453
+ ALOGE("android_recorder_setVideoSource() failed");
456
+ ret = android_recorder_setOutputFormat(recorder, ANDROID_OUTPUT_FORMAT_MPEG_4);
458
+ ALOGE("android_recorder_setOutputFormat() failed");
461
+ ret = android_recorder_setAudioEncoder(recorder, ANDROID_AUDIO_ENCODER_AAC);
463
+ ALOGE("android_recorder_setAudioEncoder() failed");
466
+ ret = android_recorder_setVideoEncoder(recorder, ANDROID_VIDEO_ENCODER_H264);
468
+ ALOGE("android_recorder_setVideoEncoder() failed");
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);
476
+ ALOGE("Couldn't open output video file for recording: %s", out_file);
479
+ ret = android_recorder_setOutputFile(recorder, fd);
481
+ ALOGE("android_recorder_setOutputFile() failed");
484
+ ret = android_recorder_setVideoSize(recorder, camera_width, camera_height);
486
+ ALOGE("android_recorder_setVideoSize() failed");
489
+ ret = android_recorder_setVideoFrameRate(recorder, 30);
491
+ ALOGE("android_recorder_setVideoFrameRate() failed");
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);
502
+ ALOGE("android_recorder_prepare() failed");
505
+ ALOGD("Starting video recording");
506
+ ret = android_recorder_start(recorder);
508
+ ALOGE("android_recorder_start() failed");
515
+static void stop_video_recording(MediaRecorderWrapper *recorder)
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");
526
+void on_new_input_event(Event* event, void* context)
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);
533
+ CameraControl* cc = static_cast<CameraControl*>(context);
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);
541
+ case ISCL_KEYCODE_VOLUME_DOWN:
542
+ printf("Stopping video recording\n");
543
+ stop_video_recording(recorder);
546
+ case ISCL_KEYCODE_POWER:
547
+ printf("\tTaking a photo now.\n");
548
+ android_camera_take_snapshot(cc);
550
+ case ISCL_KEYCODE_HEADSETHOOK:
551
+ printf("\tSwitching effect.\n");
552
+ android_camera_set_effect_mode(cc, next_effect());
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);
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);
570
+struct ClientWithSurface
573
+ SfSurface* surface;
576
+ClientWithSurface client_with_surface(bool setup_surface_with_egl)
578
+ ClientWithSurface cs = ClientWithSurface();
580
+ cs.client = sf_client_create();
583
+ printf("Problem creating client ... aborting now.");
587
+ static const size_t primary_display = 0;
589
+ SfSurfaceCreationParameters params = {
592
+ (int) sf_get_display_width(primary_display),
593
+ (int) sf_get_display_height(primary_display),
594
+ -1, //PIXEL_FORMAT_RGBA_8888,
597
+ setup_surface_with_egl, // Do not associate surface with egl, will be done by camera HAL
598
+ "CameraCompatLayerTestSurface"
601
+ cs.surface = sf_surface_create(cs.client, ¶ms);
604
+ printf("Problem creating surface ... aborting now.");
608
+ sf_surface_make_current(cs.surface);
613
+#define PRINT_GLERROR() printf("GL error@%d: %x\n", __LINE__, glGetError());
615
int main(int argc, char** argv)
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,
627
+ if (camera_control == NULL) {
628
printf("Problem connecting to camera");
632
- listener.context = cc;
633
+ listener.context = camera_control;
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;
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
648
android_input_stack_initialize(&event_listener, &input_configuration);
649
android_input_stack_start();
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;
659
+ android_camera_set_picture_size(camera_control, camera_width, camera_height);
661
+ AutoFocusMode af_mode;
662
+ android_camera_get_auto_focus_mode(camera_control, &af_mode);
663
+ printf("Current af mode: %d \n", af_mode);
666
+ android_camera_set_zoom(camera_control, 0);
667
+ android_camera_get_max_zoom(camera_control, &zoom);
668
+ printf("Max zoom: %d \n", zoom);
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);
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, ¤t_fps);
679
+ android_camera_get_preview_fps(camera_control, ¤t_fps);
680
printf("Current preview fps range: %d\n", current_fps);
682
- android_camera_set_preview_size(cc, 960, 720);
684
+ android_camera_dump_parameters(camera_control);
686
+ android_camera_set_display_orientation(camera_control, 90);
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);
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);
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);
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);
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);
734
+ printf("Creating client with surface");
735
ClientWithSurface cs = client_with_surface(true /* Associate surface with egl. */);
738
printf("Problem acquiring surface for preview");
741
+ printf("Finished creating client with surface\n");
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);
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);
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);
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);
770
+ android_camera_start_preview(camera_control);
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);
777
printf("Started camera preview.\n");
780
- /*if (new_camera_frame_available)
782
- printf("Updating texture");
783
- new_camera_frame_available = false;
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
795
- GLushort indices[] = { 0, 1, 2, 0, 2, 3 };
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,
810
- 5 * sizeof(GLfloat),
812
- // Load the texture coordinate
813
- glVertexAttribPointer(render_data.tex_coord_loc,
817
- 5 * sizeof(GLfloat),
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);
829
- eglSwapBuffers(disp, surface);
834
+ stop_video_recording(recorder);
835
+ android_camera_stop_preview(camera_control);
836
+ android_camera_disconnect(camera_control);
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 := \
4737
5521
+#endif // MEDIA_FORMAT_LAYER_PRIV_H_
4739
+++ libhybris-0.1.0+git20131207+e452e83/compat/media/recorder_compatibility_layer.cpp
4742
+ * Copyright (C) 2013 Canonical Ltd
5523
+++ libhybris-0.1.0+git20131207+e452e83/compat/media/media_recorder.cpp
5526
+ ** Copyright (c) 2008 The Android Open Source Project
5527
+ ** Copyright (C) 2014 Canonical Ltd
5529
+ ** Adapted from the Android equivalent code for use in Ubuntu.
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
5535
+ ** http://www.apache.org/licenses/LICENSE-2.0
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.
5544
+//#define LOG_NDEBUG 0
5545
+#define LOG_TAG "MediaRecorder"
5547
+#include "media_recorder.h"
5548
+#include "media_recorder_factory.h"
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>
5558
+namespace android {
5560
+status_t MediaRecorder::setCamera(const sp<ICamera>& camera, const sp<ICameraRecordingProxy>& proxy)
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;
5567
+ if (!(mCurrentState & MEDIA_RECORDER_IDLE)) {
5568
+ ALOGE("setCamera called in an invalid state(%d)", mCurrentState);
5569
+ return INVALID_OPERATION;
5572
+ status_t ret = mMediaRecorder->setCamera(camera, proxy);
5574
+ ALOGV("setCamera failed: %d", ret);
5575
+ mCurrentState = MEDIA_RECORDER_ERROR;
5581
+status_t MediaRecorder::setPreviewSurface(const sp<IGraphicBufferProducer>& surface)
5583
+ ALOGV("setPreviewSurface(%p)", surface.get());
5584
+ if (mMediaRecorder == NULL) {
5585
+ ALOGE("media recorder is not initialized yet");
5586
+ return INVALID_OPERATION;
5588
+ if (!(mCurrentState & MEDIA_RECORDER_DATASOURCE_CONFIGURED)) {
5589
+ ALOGE("setPreviewSurface called in an invalid state(%d)", mCurrentState);
5590
+ return INVALID_OPERATION;
5592
+ if (!mIsVideoSourceSet) {
5593
+ ALOGE("try to set preview surface without setting the video source first");
5594
+ return INVALID_OPERATION;
5597
+ status_t ret = mMediaRecorder->setPreviewSurface(surface);
5599
+ ALOGV("setPreviewSurface failed: %d", ret);
5600
+ mCurrentState = MEDIA_RECORDER_ERROR;
5606
+status_t MediaRecorder::init()
5609
+ if (mMediaRecorder == NULL) {
5610
+ ALOGE("media recorder is not initialized yet");
5611
+ return INVALID_OPERATION;
5613
+ if (!(mCurrentState & MEDIA_RECORDER_IDLE)) {
5614
+ ALOGE("init called in an invalid state(%d)", mCurrentState);
5615
+ return INVALID_OPERATION;
5618
+ status_t ret = mMediaRecorder->init();
5620
+ ALOGV("init failed: %d", ret);
5621
+ mCurrentState = MEDIA_RECORDER_ERROR;
5625
+ ret = mMediaRecorder->setListener(this);
5627
+ ALOGV("setListener failed: %d", ret);
5628
+ mCurrentState = MEDIA_RECORDER_ERROR;
5632
+ mCurrentState = MEDIA_RECORDER_INITIALIZED;
5636
+status_t MediaRecorder::setVideoSource(int vs)
5638
+ ALOGV("setVideoSource(%d)", vs);
5639
+ if (mMediaRecorder == NULL) {
5640
+ ALOGE("media recorder is not initialized yet");
5641
+ return INVALID_OPERATION;
5643
+ if (mIsVideoSourceSet) {
5644
+ ALOGE("video source has already been set");
5645
+ return INVALID_OPERATION;
5647
+ if (mCurrentState & MEDIA_RECORDER_IDLE) {
5648
+ ALOGV("Call init() since the media recorder is not initialized yet");
5649
+ status_t ret = init();
5654
+ if (!(mCurrentState & MEDIA_RECORDER_INITIALIZED)) {
5655
+ ALOGE("setVideoSource called in an invalid state(%d)", mCurrentState);
5656
+ return INVALID_OPERATION;
5659
+ // following call is made over the Binder Interface
5660
+ status_t ret = mMediaRecorder->setVideoSource(vs);
5663
+ ALOGV("setVideoSource failed: %d", ret);
5664
+ mCurrentState = MEDIA_RECORDER_ERROR;
5667
+ mIsVideoSourceSet = true;
5671
+status_t MediaRecorder::setAudioSource(int as)
5673
+ ALOGV("setAudioSource(%d)", as);
5674
+ if (mMediaRecorder == NULL) {
5675
+ ALOGE("media recorder is not initialized yet");
5676
+ return INVALID_OPERATION;
5678
+ if (mCurrentState & MEDIA_RECORDER_IDLE) {
5679
+ ALOGV("Call init() since the media recorder is not initialized yet");
5680
+ status_t ret = init();
5685
+ if (mIsAudioSourceSet) {
5686
+ ALOGE("audio source has already been set");
5687
+ return INVALID_OPERATION;
5689
+ if (!(mCurrentState & MEDIA_RECORDER_INITIALIZED)) {
5690
+ ALOGE("setAudioSource called in an invalid state(%d)", mCurrentState);
5691
+ return INVALID_OPERATION;
5694
+ status_t ret = mMediaRecorder->setAudioSource(as);
5696
+ ALOGV("setAudioSource failed: %d", ret);
5697
+ mCurrentState = MEDIA_RECORDER_ERROR;
5700
+ mIsAudioSourceSet = true;
5704
+status_t MediaRecorder::setOutputFormat(int of)
5706
+ ALOGV("setOutputFormat(%d)", of);
5707
+ if (mMediaRecorder == NULL) {
5708
+ ALOGE("media recorder is not initialized yet");
5709
+ return INVALID_OPERATION;
5711
+ if (!(mCurrentState & MEDIA_RECORDER_INITIALIZED)) {
5712
+ ALOGE("setOutputFormat called in an invalid state: %d", mCurrentState);
5713
+ return INVALID_OPERATION;
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;
5720
+ status_t ret = mMediaRecorder->setOutputFormat(of);
5722
+ ALOGE("setOutputFormat failed: %d", ret);
5723
+ mCurrentState = MEDIA_RECORDER_ERROR;
5726
+ mCurrentState = MEDIA_RECORDER_DATASOURCE_CONFIGURED;
5730
+status_t MediaRecorder::setVideoEncoder(int ve)
5732
+ ALOGV("setVideoEncoder(%d)", ve);
5733
+ if (mMediaRecorder == NULL) {
5734
+ ALOGE("media recorder is not initialized yet");
5735
+ return INVALID_OPERATION;
5737
+ if (!mIsVideoSourceSet) {
5738
+ ALOGE("try to set the video encoder without setting the video source first");
5739
+ return INVALID_OPERATION;
5741
+ if (mIsVideoEncoderSet) {
5742
+ ALOGE("video encoder has already been set");
5743
+ return INVALID_OPERATION;
5745
+ if (!(mCurrentState & MEDIA_RECORDER_DATASOURCE_CONFIGURED)) {
5746
+ ALOGE("setVideoEncoder called in an invalid state(%d)", mCurrentState);
5747
+ return INVALID_OPERATION;
5750
+ status_t ret = mMediaRecorder->setVideoEncoder(ve);
5752
+ ALOGV("setVideoEncoder failed: %d", ret);
5753
+ mCurrentState = MEDIA_RECORDER_ERROR;
5756
+ mIsVideoEncoderSet = true;
5760
+status_t MediaRecorder::setAudioEncoder(int ae)
5762
+ ALOGV("setAudioEncoder(%d)", ae);
5763
+ if (mMediaRecorder == NULL) {
5764
+ ALOGE("media recorder is not initialized yet");
5765
+ return INVALID_OPERATION;
5767
+ if (!mIsAudioSourceSet) {
5768
+ ALOGE("try to set the audio encoder without setting the audio source first");
5769
+ return INVALID_OPERATION;
5771
+ if (mIsAudioEncoderSet) {
5772
+ ALOGE("audio encoder has already been set");
5773
+ return INVALID_OPERATION;
5775
+ if (!(mCurrentState & MEDIA_RECORDER_DATASOURCE_CONFIGURED)) {
5776
+ ALOGE("setAudioEncoder called in an invalid state(%d)", mCurrentState);
5777
+ return INVALID_OPERATION;
5780
+ status_t ret = mMediaRecorder->setAudioEncoder(ae);
5782
+ ALOGV("setAudioEncoder failed: %d", ret);
5783
+ mCurrentState = MEDIA_RECORDER_ERROR;
5786
+ mIsAudioEncoderSet = true;
5790
+status_t MediaRecorder::setOutputFile(const char* path)
5792
+ ALOGV("setOutputFile(%s)", path);
5793
+ if (mMediaRecorder == NULL) {
5794
+ ALOGE("media recorder is not initialized yet");
5795
+ return INVALID_OPERATION;
5797
+ if (mIsOutputFileSet) {
5798
+ ALOGE("output file has already been set");
5799
+ return INVALID_OPERATION;
5801
+ if (!(mCurrentState & MEDIA_RECORDER_DATASOURCE_CONFIGURED)) {
5802
+ ALOGE("setOutputFile called in an invalid state(%d)", mCurrentState);
5803
+ return INVALID_OPERATION;
5806
+ status_t ret = mMediaRecorder->setOutputFile(path);
5808
+ ALOGV("setOutputFile failed: %d", ret);
5809
+ mCurrentState = MEDIA_RECORDER_ERROR;
5812
+ mIsOutputFileSet = true;
5816
+status_t MediaRecorder::setOutputFile(int fd, int64_t offset, int64_t length)
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;
5823
+ if (mIsOutputFileSet) {
5824
+ ALOGE("output file has already been set");
5825
+ return INVALID_OPERATION;
5827
+ if (!(mCurrentState & MEDIA_RECORDER_DATASOURCE_CONFIGURED)) {
5828
+ ALOGE("setOutputFile called in an invalid state(%d)", mCurrentState);
5829
+ return INVALID_OPERATION;
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.
5839
+ ALOGE("Invalid file descriptor: %d", fd);
5843
+ status_t ret = mMediaRecorder->setOutputFile(fd, offset, length);
5845
+ ALOGV("setOutputFile failed: %d", ret);
5846
+ mCurrentState = MEDIA_RECORDER_ERROR;
5849
+ mIsOutputFileSet = true;
5853
+status_t MediaRecorder::setVideoSize(int width, int height)
5855
+ ALOGV("setVideoSize(%d, %d)", width, height);
5856
+ if (mMediaRecorder == NULL) {
5857
+ ALOGE("media recorder is not initialized yet");
5858
+ return INVALID_OPERATION;
5860
+ if (!(mCurrentState & MEDIA_RECORDER_DATASOURCE_CONFIGURED)) {
5861
+ ALOGE("setVideoSize called in an invalid state: %d", mCurrentState);
5862
+ return INVALID_OPERATION;
5864
+ if (!mIsVideoSourceSet) {
5865
+ ALOGE("Cannot set video size without setting video source first");
5866
+ return INVALID_OPERATION;
5869
+ status_t ret = mMediaRecorder->setVideoSize(width, height);
5871
+ ALOGE("setVideoSize failed: %d", ret);
5872
+ mCurrentState = MEDIA_RECORDER_ERROR;
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()
5885
+ Mutex::Autolock _l(mLock);
5886
+ mSurfaceMediaSource =
5887
+ mMediaRecorder->querySurfaceMediaSource();
5888
+ if (mSurfaceMediaSource == NULL) {
5889
+ ALOGE("SurfaceMediaSource could not be initialized!");
5891
+ return mSurfaceMediaSource;
5894
+status_t MediaRecorder::setVideoFrameRate(int frames_per_second)
5896
+ ALOGV("setVideoFrameRate(%d)", frames_per_second);
5897
+ if (mMediaRecorder == NULL) {
5898
+ ALOGE("media recorder is not initialized yet");
5899
+ return INVALID_OPERATION;
5901
+ if (!(mCurrentState & MEDIA_RECORDER_DATASOURCE_CONFIGURED)) {
5902
+ ALOGE("setVideoFrameRate called in an invalid state: %d", mCurrentState);
5903
+ return INVALID_OPERATION;
5905
+ if (!mIsVideoSourceSet) {
5906
+ ALOGE("Cannot set video frame rate without setting video source first");
5907
+ return INVALID_OPERATION;
5910
+ status_t ret = mMediaRecorder->setVideoFrameRate(frames_per_second);
5912
+ ALOGE("setVideoFrameRate failed: %d", ret);
5913
+ mCurrentState = MEDIA_RECORDER_ERROR;
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;
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;
5935
+ status_t ret = mMediaRecorder->setParameters(params);
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.
5946
+status_t MediaRecorder::prepare()
5949
+ if (mMediaRecorder == NULL) {
5950
+ ALOGE("media recorder is not initialized yet");
5951
+ return INVALID_OPERATION;
5953
+ if (!(mCurrentState & MEDIA_RECORDER_DATASOURCE_CONFIGURED)) {
5954
+ ALOGE("prepare called in an invalid state: %d", mCurrentState);
5955
+ return INVALID_OPERATION;
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");
5963
+ return INVALID_OPERATION;
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");
5972
+ return INVALID_OPERATION;
5975
+ status_t ret = mMediaRecorder->prepare();
5977
+ ALOGE("prepare failed: %d", ret);
5978
+ mCurrentState = MEDIA_RECORDER_ERROR;
5981
+ mCurrentState = MEDIA_RECORDER_PREPARED;
5985
+status_t MediaRecorder::getMaxAmplitude(int* max)
5987
+ ALOGV("getMaxAmplitude");
5988
+ if (mMediaRecorder == NULL) {
5989
+ ALOGE("media recorder is not initialized yet");
5990
+ return INVALID_OPERATION;
5992
+ if (mCurrentState & MEDIA_RECORDER_ERROR) {
5993
+ ALOGE("getMaxAmplitude called in an invalid state: %d", mCurrentState);
5994
+ return INVALID_OPERATION;
5997
+ status_t ret = mMediaRecorder->getMaxAmplitude(max);
5999
+ ALOGE("getMaxAmplitude failed: %d", ret);
6000
+ mCurrentState = MEDIA_RECORDER_ERROR;
6006
+status_t MediaRecorder::start()
6009
+ if (mMediaRecorder == NULL) {
6010
+ ALOGE("media recorder is not initialized yet");
6011
+ return INVALID_OPERATION;
6013
+ if (!(mCurrentState & MEDIA_RECORDER_PREPARED)) {
6014
+ ALOGE("start called in an invalid state: %d", mCurrentState);
6015
+ return INVALID_OPERATION;
6018
+ status_t ret = mMediaRecorder->start();
6020
+ ALOGE("start failed: %d", ret);
6021
+ mCurrentState = MEDIA_RECORDER_ERROR;
6024
+ mCurrentState = MEDIA_RECORDER_RECORDING;
6028
+status_t MediaRecorder::stop()
6031
+ if (mMediaRecorder == NULL) {
6032
+ ALOGE("media recorder is not initialized yet");
6033
+ return INVALID_OPERATION;
6035
+ if (!(mCurrentState & MEDIA_RECORDER_RECORDING)) {
6036
+ ALOGE("stop called in an invalid state: %d", mCurrentState);
6037
+ return INVALID_OPERATION;
6040
+ status_t ret = mMediaRecorder->stop();
6042
+ ALOGE("stop failed: %d", ret);
6043
+ mCurrentState = MEDIA_RECORDER_ERROR;
6048
+ // stop and reset are semantically different.
6049
+ // We treat them the same for now, and will change this in the future.
6051
+ mCurrentState = MEDIA_RECORDER_IDLE;
6055
+// Reset should be OK in any state
6056
+status_t MediaRecorder::reset()
6059
+ if (mMediaRecorder == NULL) {
6060
+ ALOGE("media recorder is not initialized yet");
6061
+ return INVALID_OPERATION;
6065
+ status_t ret = UNKNOWN_ERROR;
6066
+ switch (mCurrentState) {
6067
+ case MEDIA_RECORDER_IDLE:
6071
+ case MEDIA_RECORDER_RECORDING:
6072
+ case MEDIA_RECORDER_DATASOURCE_CONFIGURED:
6073
+ case MEDIA_RECORDER_PREPARED:
6074
+ case MEDIA_RECORDER_ERROR: {
6077
+ return ret; // No need to continue
6079
+ } // Intentional fall through
6080
+ case MEDIA_RECORDER_INITIALIZED:
6085
+ ALOGE("Unexpected non-existing state: %d", mCurrentState);
6092
+status_t MediaRecorder::close()
6095
+ if (!(mCurrentState & MEDIA_RECORDER_INITIALIZED)) {
6096
+ ALOGE("close called in an invalid state: %d", mCurrentState);
6097
+ return INVALID_OPERATION;
6099
+ status_t ret = mMediaRecorder->close();
6101
+ ALOGE("close failed: %d", ret);
6102
+ mCurrentState = MEDIA_RECORDER_ERROR;
6103
+ return UNKNOWN_ERROR;
6105
+ mCurrentState = MEDIA_RECORDER_IDLE;
6110
+status_t MediaRecorder::doReset()
6113
+ status_t ret = mMediaRecorder->reset();
6115
+ ALOGE("doReset failed: %d", ret);
6116
+ mCurrentState = MEDIA_RECORDER_ERROR;
6119
+ mCurrentState = MEDIA_RECORDER_INITIALIZED;
6124
+void MediaRecorder::doCleanUp()
6126
+ ALOGV("doCleanUp");
6127
+ mIsAudioSourceSet = false;
6128
+ mIsVideoSourceSet = false;
6129
+ mIsAudioEncoderSet = false;
6130
+ mIsVideoEncoderSet = false;
6131
+ mIsOutputFileSet = false;
6134
+// Release should be OK in any state
6135
+status_t MediaRecorder::release()
6138
+ if (mMediaRecorder != NULL) {
6139
+ return mMediaRecorder->release();
6141
+ return INVALID_OPERATION;
6145
+MediaRecorder::MediaRecorder()
6146
+ : mMediaRecorderFactory(NULL),
6147
+ mSurfaceMediaSource(NULL)
6149
+ ALOGV("constructor (custom)");
6151
+ if (mMediaRecorderFactory == NULL) {
6152
+ sp<IServiceManager> sm = defaultServiceManager();
6153
+ sp<IBinder> binder;
6155
+ binder = sm->getService(String16(IMediaRecorderFactory::exported_service_name()));
6156
+ if (binder != 0) {
6159
+ ALOGW("MediaRecorderFactory service not published, waiting...");
6160
+ usleep(500000); // 0.5 s
6163
+ mMediaRecorderFactory = interface_cast<IMediaRecorderFactory>(binder);
6166
+ ALOGE_IF(mMediaRecorderFactory == NULL, "no MediaRecorderFactory!?");
6168
+ mMediaRecorder = mMediaRecorderFactory->createMediaRecorder();
6169
+ if (mMediaRecorder != NULL) {
6170
+ mCurrentState = MEDIA_RECORDER_IDLE;
6176
+status_t MediaRecorder::initCheck()
6178
+ return mMediaRecorder != 0 ? NO_ERROR : NO_INIT;
6181
+MediaRecorder::~MediaRecorder()
6183
+ ALOGV("destructor");
6184
+ if (mMediaRecorder != NULL) {
6185
+ mMediaRecorder.clear();
6188
+ if (mSurfaceMediaSource != NULL) {
6189
+ mSurfaceMediaSource.clear();
6193
+status_t MediaRecorder::setListener(const sp<MediaRecorderListener>& listener)
6195
+ ALOGV("setListener");
6196
+ Mutex::Autolock _l(mLock);
6197
+ mListener = listener;
6202
+status_t MediaRecorder::setClientName(const String16& clientName)
6204
+ ALOGV("setClientName");
6205
+ if (mMediaRecorder == NULL) {
6206
+ ALOGE("media recorder is not initialized yet");
6207
+ return INVALID_OPERATION;
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;
6218
+ mMediaRecorder->setClientName(clientName);
6223
+void MediaRecorder::notify(int msg, int ext1, int ext2)
6225
+ ALOGV("message received msg=%d, ext1=%d, ext2=%d", msg, ext1, ext2);
6227
+ sp<MediaRecorderListener> listener;
6229
+ listener = mListener;
6232
+ if (listener != NULL) {
6233
+ Mutex::Autolock _l(mNotifyLock);
6234
+ ALOGV("callback application");
6235
+ listener->notify(msg, ext1, ext2);
6236
+ ALOGV("back from callback");
6240
+void MediaRecorder::died()
6243
+ notify(MEDIA_RECORDER_EVENT_ERROR, MEDIA_ERROR_SERVER_DIED, 0);
6246
+} // namespace android
6248
+++ libhybris-0.1.0+git20131207+e452e83/compat/media/media_recorder.h
6251
+ ** Copyright (C) 2008 The Android Open Source Project
6252
+ ** Copyright (C) 2014 Canonical Ltd
6254
+ ** Adapted from the Android equivalent code for use in Ubuntu.
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
6260
+ ** http://www.apache.org/licenses/LICENSE-2.0
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
6267
+ ** limitations under the License.
6270
+#ifndef ANDROID_MEDIARECORDER_H
6271
+#define ANDROID_MEDIARECORDER_H
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>
6280
+namespace android {
6283
+class IMediaRecorder;
6284
+class IMediaRecorderFactory;
6286
+class ICameraRecordingProxy;
6287
+class IGraphicBufferProducer;
6290
+typedef void (*media_completion_f)(status_t status, void *cookie);
6292
+enum video_source {
6293
+ VIDEO_SOURCE_DEFAULT = 0,
6294
+ VIDEO_SOURCE_CAMERA = 1,
6295
+ VIDEO_SOURCE_GRALLOC_BUFFER = 2,
6297
+ VIDEO_SOURCE_LIST_END // must be last - used to validate audio source type
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,
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.
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,
6317
+ /* Stream over a socket, limited to a single stream */
6318
+ OUTPUT_FORMAT_RTP_AVP = 7,
6320
+ /* H.264/AAC data encapsulated in MPEG2/TS */
6321
+ OUTPUT_FORMAT_MPEG2TS = 8,
6323
+ OUTPUT_FORMAT_LIST_END // must be last - used to validate format type
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,
6334
+ AUDIO_ENCODER_LIST_END // must be the last - used to validate the audio encoder type
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,
6343
+ VIDEO_ENCODER_LIST_END // must be the last - used to validate the video encoder type
6347
+ * The state machine of the media_recorder.
6349
+enum media_recorder_states {
6351
+ MEDIA_RECORDER_ERROR = 0,
6353
+ // Recorder was just created.
6354
+ MEDIA_RECORDER_IDLE = 1 << 0,
6356
+ // Recorder has been initialized.
6357
+ MEDIA_RECORDER_INITIALIZED = 1 << 1,
6359
+ // Configuration of the recorder has been completed.
6360
+ MEDIA_RECORDER_DATASOURCE_CONFIGURED = 1 << 2,
6362
+ // Recorder is ready to start.
6363
+ MEDIA_RECORDER_PREPARED = 1 << 3,
6365
+ // Recording is in progress.
6366
+ MEDIA_RECORDER_RECORDING = 1 << 4,
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,
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,
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.
6391
+ * | track id | reserved | error or info type |
6395
+enum media_recorder_error_type {
6396
+ MEDIA_RECORDER_ERROR_UNKNOWN = 1,
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,
6405
+// The codes are distributed as follow:
6407
+// 8xx: General info/warning
6409
+enum media_recorder_info_type {
6410
+ MEDIA_RECORDER_INFO_UNKNOWN = 1,
6412
+ MEDIA_RECORDER_INFO_MAX_DURATION_REACHED = 800,
6413
+ MEDIA_RECORDER_INFO_MAX_FILESIZE_REACHED = 801,
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,
6422
+ // The time to measure the max chunk duration
6423
+ MEDIA_RECORDER_TRACK_INFO_MAX_CHUNK_DUR_MS = 1004,
6425
+ MEDIA_RECORDER_TRACK_INFO_ENCODED_FRAMES = 1005,
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,
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,
6436
+ // The time used to compensate for initial A/V sync.
6437
+ MEDIA_RECORDER_TRACK_INFO_START_OFFSET_MS = 1008,
6439
+ // Total number of bytes of the media data.
6440
+ MEDIA_RECORDER_TRACK_INFO_DATA_KBYTES = 1009,
6442
+ MEDIA_RECORDER_TRACK_INFO_LIST_END = 2000,
6445
+class MediaPlayerService;
6447
+// ----------------------------------------------------------------------------
6448
+// ref-counted object for callbacks
6449
+class MediaRecorderListener: virtual public RefBase
6452
+ virtual void notify(int msg, int ext1, int ext2) = 0;
6455
+class MediaRecorder : public BnMediaRecorderClient,
6456
+ public virtual IMediaDeathNotifier
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);
6485
+ status_t release();
6486
+ void notify(int msg, int ext1, int ext2);
6487
+ sp<IGraphicBufferProducer> querySurfaceMediaSourceFromMediaServer();
6491
+ status_t doReset();
6493
+ sp<IMediaRecorder> mMediaRecorder;
6494
+ sp<MediaRecorderListener> mListener;
6495
+ sp<IMediaRecorderFactory> mMediaRecorderFactory;
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;
6502
+ media_recorder_states mCurrentState;
6503
+ bool mIsAudioSourceSet;
6504
+ bool mIsVideoSourceSet;
6505
+ bool mIsAudioEncoderSet;
6506
+ bool mIsVideoEncoderSet;
6507
+ bool mIsOutputFileSet;
6509
+ Mutex mNotifyLock;
6512
+}; // namespace android
6514
+#endif // ANDROID_MEDIARECORDER_H
6516
+++ libhybris-0.1.0+git20131207+e452e83/compat/media/media_recorder_client.cpp
6519
+ * Copyright (C) 2013-2014 Canonical Ltd
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
6525
+ * http://www.apache.org/licenses/LICENSE-2.0
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.
6533
+ * Authored by: Jim Hodapp <jim.hodapp@canonical.com>
6536
+#include "media_recorder_client.h"
6538
+#include <libmediaplayerservice/StagefrightRecorder.h>
6540
+#include <utils/Log.h>
6542
+#define LOG_NDEBUG 0
6543
+#define LOG_TAG "MediaRecorderClient"
6545
+#define REPORT_FUNCTION() ALOGV("%s \n", __PRETTY_FUNCTION__)
6547
+using namespace android;
6549
+MediaRecorderClient::MediaRecorderClient()
6551
+ REPORT_FUNCTION();
6552
+ recorder = new android::StagefrightRecorder;
6555
+MediaRecorderClient::~MediaRecorderClient()
6557
+ REPORT_FUNCTION();
6561
+status_t MediaRecorderClient::setCamera(const sp<android::ICamera>& camera,
6562
+ const sp<ICameraRecordingProxy>& proxy)
6564
+ REPORT_FUNCTION();
6565
+ Mutex::Autolock lock(recorder_lock);
6566
+ if (recorder == NULL) {
6567
+ ALOGE("recorder must not be NULL");
6570
+ return recorder->setCamera(camera, proxy);
6573
+status_t MediaRecorderClient::setPreviewSurface(const android::sp<android::IGraphicBufferProducer>& surface)
6575
+ REPORT_FUNCTION();
6576
+ Mutex::Autolock lock(recorder_lock);
6577
+ if (recorder == NULL) {
6578
+ ALOGE("recorder must not be NULL");
6581
+ return recorder->setPreviewSurface(surface);
6584
+status_t MediaRecorderClient::setVideoSource(int vs)
6586
+ REPORT_FUNCTION();
6587
+ Mutex::Autolock lock(recorder_lock);
6588
+ if (recorder == NULL) {
6589
+ ALOGE("recorder must not be NULL");
6592
+ return recorder->setVideoSource((android::video_source)vs);
6595
+status_t MediaRecorderClient::setAudioSource(int as)
6597
+ REPORT_FUNCTION();
6598
+ Mutex::Autolock lock(recorder_lock);
6599
+ if (recorder == NULL) {
6600
+ ALOGE("recorder must not be NULL");
6603
+ return recorder->setAudioSource((audio_source_t)as);
6606
+status_t MediaRecorderClient::setOutputFormat(int of)
6608
+ REPORT_FUNCTION();
6609
+ Mutex::Autolock lock(recorder_lock);
6610
+ if (recorder == NULL) {
6611
+ ALOGE("recorder must not be NULL");
6614
+ return recorder->setOutputFormat((android::output_format)of);
6617
+status_t MediaRecorderClient::setVideoEncoder(int ve)
6619
+ REPORT_FUNCTION();
6620
+ Mutex::Autolock lock(recorder_lock);
6621
+ if (recorder == NULL) {
6622
+ ALOGE("recorder must not be NULL");
6625
+ return recorder->setVideoEncoder((android::video_encoder)ve);
6628
+status_t MediaRecorderClient::setAudioEncoder(int ae)
6630
+ REPORT_FUNCTION();
6631
+ Mutex::Autolock lock(recorder_lock);
6632
+ if (recorder == NULL) {
6633
+ ALOGE("recorder must not be NULL");
6636
+ return recorder->setAudioEncoder((android::audio_encoder)ae);
6639
+status_t MediaRecorderClient::setOutputFile(const char* path)
6641
+ REPORT_FUNCTION();
6642
+ Mutex::Autolock lock(recorder_lock);
6643
+ if (recorder == NULL) {
6644
+ ALOGE("recorder must not be NULL");
6647
+ return recorder->setOutputFile(path);
6650
+status_t MediaRecorderClient::setOutputFile(int fd, int64_t offset, int64_t length)
6652
+ REPORT_FUNCTION();
6653
+ Mutex::Autolock lock(recorder_lock);
6654
+ if (recorder == NULL) {
6655
+ ALOGE("recorder must not be NULL");
6658
+ return recorder->setOutputFile(fd, offset, length);
6661
+status_t MediaRecorderClient::setVideoSize(int width, int height)
6663
+ REPORT_FUNCTION();
6664
+ Mutex::Autolock lock(recorder_lock);
6665
+ if (recorder == NULL) {
6666
+ ALOGE("recorder must not be NULL");
6669
+ return recorder->setVideoSize(width, height);
6672
+status_t MediaRecorderClient::setVideoFrameRate(int frames_per_second)
6674
+ REPORT_FUNCTION();
6675
+ Mutex::Autolock lock(recorder_lock);
6676
+ if (recorder == NULL) {
6677
+ ALOGE("recorder must not be NULL");
6680
+ return recorder->setVideoFrameRate(frames_per_second);
6683
+status_t MediaRecorderClient::setParameters(const android::String8& params)
6685
+ REPORT_FUNCTION();
6686
+ Mutex::Autolock lock(recorder_lock);
6687
+ if (recorder == NULL) {
6688
+ ALOGE("recorder must not be NULL");
6691
+ return recorder->setParameters(params);
6694
+status_t MediaRecorderClient::setListener(const android::sp<android::IMediaRecorderClient>& listener)
6696
+ REPORT_FUNCTION();
6697
+ Mutex::Autolock lock(recorder_lock);
6698
+ if (recorder == NULL) {
6699
+ ALOGE("recorder must not be NULL");
6702
+ return recorder->setListener(listener);
6705
+status_t MediaRecorderClient::setClientName(const android::String16& clientName)
6707
+ REPORT_FUNCTION();
6708
+ Mutex::Autolock lock(recorder_lock);
6709
+ if (recorder == NULL) {
6710
+ ALOGE("recorder must not be NULL");
6713
+ return recorder->setClientName(clientName);
6716
+status_t MediaRecorderClient::prepare()
6718
+ REPORT_FUNCTION();
6719
+ Mutex::Autolock lock(recorder_lock);
6720
+ if (recorder == NULL) {
6721
+ ALOGE("recorder must not be NULL");
6724
+ return recorder->prepare();
6727
+status_t MediaRecorderClient::getMaxAmplitude(int* max)
6729
+ REPORT_FUNCTION();
6730
+ Mutex::Autolock lock(recorder_lock);
6731
+ if (recorder == NULL) {
6732
+ ALOGE("recorder must not be NULL");
6735
+ return recorder->getMaxAmplitude(max);
6738
+status_t MediaRecorderClient::start()
6740
+ REPORT_FUNCTION();
6741
+ Mutex::Autolock lock(recorder_lock);
6742
+ if (recorder == NULL) {
6743
+ ALOGE("recorder must not be NULL");
6746
+ return recorder->start();
6749
+status_t MediaRecorderClient::stop()
6751
+ REPORT_FUNCTION();
6752
+ Mutex::Autolock lock(recorder_lock);
6753
+ if (recorder == NULL) {
6754
+ ALOGE("recorder must not be NULL");
6757
+ return recorder->stop();
6760
+status_t MediaRecorderClient::reset()
6762
+ REPORT_FUNCTION();
6763
+ Mutex::Autolock lock(recorder_lock);
6764
+ if (recorder == NULL) {
6765
+ ALOGE("recorder must not be NULL");
6768
+ return recorder->reset();
6771
+status_t MediaRecorderClient::init()
6773
+ REPORT_FUNCTION();
6774
+ Mutex::Autolock lock(recorder_lock);
6775
+ if (recorder == NULL) {
6776
+ ALOGE("recorder must not be NULL");
6779
+ return recorder->init();
6782
+status_t MediaRecorderClient::close()
6784
+ REPORT_FUNCTION();
6785
+ Mutex::Autolock lock(recorder_lock);
6786
+ if (recorder == NULL) {
6787
+ ALOGE("recorder must not be NULL");
6790
+ return recorder->close();
6793
+status_t MediaRecorderClient::release()
6795
+ REPORT_FUNCTION();
6796
+ Mutex::Autolock lock(recorder_lock);
6797
+ if (recorder != NULL) {
6804
+status_t MediaRecorderClient::dump(int fd, const Vector<String16>& args) const
6806
+ REPORT_FUNCTION();
6807
+ if (recorder != NULL) {
6808
+ return recorder->dump(fd, args);
6810
+ return android::OK;
6813
+sp<IGraphicBufferProducer> MediaRecorderClient::querySurfaceMediaSource()
6815
+ REPORT_FUNCTION();
6816
+ Mutex::Autolock lock(recorder_lock);
6817
+ if (recorder == NULL) {
6818
+ ALOGE("recorder is not initialized");
6821
+ return recorder->querySurfaceMediaSource();
6824
+++ libhybris-0.1.0+git20131207+e452e83/compat/media/media_recorder_client.h
6827
+ * Copyright (C) 2013-2014 Canonical Ltd
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
6833
+ * http://www.apache.org/licenses/LICENSE-2.0
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.
6841
+ * Authored by: Jim Hodapp <jim.hodapp@canonical.com>
6844
+#ifndef MEDIA_RECORDER_CLIENT_H_
6845
+#define MEDIA_RECORDER_CLIENT_H_
6847
+#include <hybris/internal/camera_control.h>
6848
+#include <hybris/media/media_recorder_layer.h>
6850
+#include <media/IMediaRecorder.h>
6852
+namespace android {
6854
+class MediaRecorderBase;
6858
+ * \brief The MediaRecorderClient struct wraps the service side of the MediaRecorder class
6860
+struct MediaRecorderClient : public BnMediaRecorder
6863
+ MediaRecorderClient();
6864
+ virtual ~MediaRecorderClient();
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();
6893
+ MediaRecorderBase *recorder;
6894
+ Mutex recorder_lock;
6901
+++ libhybris-0.1.0+git20131207+e452e83/compat/media/media_recorder_factory.cpp
6904
+ * Copyright (C) 2014 Canonical Ltd
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
6910
+ * http://www.apache.org/licenses/LICENSE-2.0
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.
6918
+ * Authored by: Jim Hodapp <jim.hodapp@canonical.com>
6921
+//#define LOG_NDEBUG 0
6923
+#define LOG_TAG "MediaRecorderFactory"
6925
+#include "media_recorder_factory.h"
6926
+#include "media_recorder_client.h"
6927
+#include <hybris/media/media_recorder_layer.h>
6929
+#include <gui/IGraphicBufferProducer.h>
6930
+#include <media/IMediaRecorder.h>
6931
+#include <binder/IServiceManager.h>
6933
+#include <utils/Log.h>
6934
+#include <utils/threads.h>
6936
+#define REPORT_FUNCTION() ALOGV("%s \n", __PRETTY_FUNCTION__)
6938
+namespace android {
6941
+ CREATE_MEDIA_RECORDER = IBinder::FIRST_CALL_TRANSACTION,
6944
+class BpMediaRecorderFactory: public BpInterface<IMediaRecorderFactory>
6947
+ BpMediaRecorderFactory(const sp<IBinder>& impl)
6948
+ : BpInterface<IMediaRecorderFactory>(impl)
6952
+ virtual sp<IMediaRecorder> createMediaRecorder()
6954
+ Parcel data, reply;
6955
+ data.writeInterfaceToken(IMediaRecorderFactory::getInterfaceDescriptor());
6956
+ remote()->transact(CREATE_MEDIA_RECORDER, data, &reply);
6957
+ return interface_cast<IMediaRecorder>(reply.readStrongBinder());
6961
+// ----------------------------------------------------------------------------
6963
+IMPLEMENT_META_INTERFACE(MediaRecorderFactory, "android.media.IMediaRecorderFactory");
6965
+// ----------------------------------------------------------------------
6967
+status_t BnMediaRecorderFactory::onTransact(
6968
+ uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags)
6971
+ case CREATE_MEDIA_RECORDER: {
6972
+ CHECK_INTERFACE(IMediaRecorderFactory, data, reply);
6973
+ sp<IMediaRecorder> recorder = createMediaRecorder();
6974
+ reply->writeStrongBinder(recorder->asBinder());
6978
+ return BBinder::onTransact(code, data, reply, flags);
6982
+// ----------------------------------------------------------------------------
6984
+sp<MediaRecorderFactory> MediaRecorderFactory::media_recorder_factory;
6985
+Mutex MediaRecorderFactory::s_lock;
6987
+MediaRecorderFactory::MediaRecorderFactory()
6989
+ REPORT_FUNCTION();
6992
+MediaRecorderFactory::~MediaRecorderFactory()
6994
+ REPORT_FUNCTION();
6998
+ * \brief Creates and adds the MediaRecorderFactory service to the default Binder ServiceManager
7000
+void MediaRecorderFactory::instantiate()
7002
+ defaultServiceManager()->addService(
7003
+ String16(IMediaRecorderFactory::exported_service_name()), factory_instance());
7004
+ ALOGV("Added Binder service '%s' to ServiceManager", IMediaRecorderFactory::exported_service_name());
7008
+ * \brief Creates a new MediaRecorderClient instance over Binder
7009
+ * \return A new MediaRecorderClient instance
7011
+sp<IMediaRecorder> MediaRecorderFactory::createMediaRecorder()
7013
+ REPORT_FUNCTION();
7014
+ sp<MediaRecorderClient> recorder = new MediaRecorderClient();
7019
+ * \brief Get a reference to the MediaRecorderFactory singleton instance
7020
+ * \return The MediaRecorderFactory singleton instance
7022
+sp<MediaRecorderFactory>& MediaRecorderFactory::factory_instance()
7024
+ REPORT_FUNCTION();
7025
+ Mutex::Autolock _l(s_lock);
7026
+ if (media_recorder_factory == NULL)
7028
+ ALOGD("Creating new static instance of MediaRecorderFactory");
7029
+ media_recorder_factory = new MediaRecorderFactory();
7032
+ return media_recorder_factory;
7035
+} // namespace android
7037
+++ libhybris-0.1.0+git20131207+e452e83/compat/media/media_recorder_factory.h
7040
+ * Copyright (C) 2014 Canonical Ltd
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
7046
+ * http://www.apache.org/licenses/LICENSE-2.0
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.
7054
+ * Authored by: Jim Hodapp <jim.hodapp@canonical.com>
7057
+#ifndef MEDIA_RECORDER_FACTORY_H_
7058
+#define MEDIA_RECORDER_FACTORY_H_
7060
+#include <media/IMediaRecorder.h>
7062
+#include <binder/IInterface.h>
7063
+#include <binder/Parcel.h>
7065
+namespace android {
7069
+class IMediaRecorderFactory: public IInterface
7072
+ DECLARE_META_INTERFACE(MediaRecorderFactory);
7074
+ static const char* exported_service_name() { return "android.media.IMediaRecorderFactory"; }
7076
+ virtual sp<IMediaRecorder> createMediaRecorder() = 0;
7079
+// ----------------------------------------------------------------------------
7081
+class BnMediaRecorderFactory: public BnInterface<IMediaRecorderFactory>
7084
+ virtual status_t onTransact( uint32_t code,
7085
+ const Parcel& data,
7087
+ uint32_t flags = 0);
7090
+// ----------------------------------------------------------------------------
7092
+class MediaRecorderFactory : public BnMediaRecorderFactory
7095
+ MediaRecorderFactory();
7096
+ virtual ~MediaRecorderFactory();
7098
+ static void instantiate();
7100
+ virtual sp<IMediaRecorder> createMediaRecorder();
7102
+ static sp<MediaRecorderFactory>& factory_instance();
7104
+ static sp<MediaRecorderFactory> media_recorder_factory;
7105
+ static Mutex s_lock;
7112
+++ libhybris-0.1.0+git20131207+e452e83/compat/media/media_recorder_layer.cpp
7115
+ * Copyright (C) 2013-2014 Canonical Ltd
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.
4875
7250
+MediaRecorderWrapper *android_media_new_recorder()
4877
+ REPORT_FUNCTION();
4879
+ MediaRecorderWrapper *mr = new MediaRecorderWrapper;
4881
+ ALOGE("Failed to create new MediaRecorderWrapper instance.");
7252
+ REPORT_FUNCTION();
7254
+ MediaRecorderWrapper *mr = new MediaRecorderWrapper;
7256
+ ALOGE("Failed to create new MediaRecorder instance.");
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
4893
7268
+int android_recorder_initCheck(MediaRecorderWrapper *mr)
4895
+ REPORT_FUNCTION();
4898
+ ALOGE("mr must not be NULL");
4902
+ return mr->initCheck();
7270
+ REPORT_FUNCTION();
7273
+ ALOGE("mr must not be NULL");
7274
+ return android::BAD_VALUE;
7277
+ return mr->initCheck();
4906
+ * \brief android_recorder_setCamera sets the camera object for recording videos
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
4912
7286
+int android_recorder_setCamera(MediaRecorderWrapper *mr, CameraControl* control)
4914
+ REPORT_FUNCTION();
4917
+ ALOGE("mr must not be NULL");
4920
+ if (control == NULL) {
4921
+ ALOGE("control must not be NULL");
4925
+ return mr->setCamera(control->camera->remote(), control->camera->getRecordingProxy());
7288
+ REPORT_FUNCTION();
7291
+ ALOGE("mr must not be NULL");
7292
+ return android::BAD_VALUE;
7294
+ if (control == NULL) {
7295
+ ALOGE("control must not be NULL");
7296
+ return android::BAD_VALUE;
7299
+ return mr->setCamera(control->camera->remote(), control->camera->getRecordingProxy());
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
4935
7309
+int android_recorder_setVideoSource(MediaRecorderWrapper *mr, VideoSource vs)
4937
+ REPORT_FUNCTION();
4940
+ ALOGE("mr must not be NULL");
4944
+ return mr->setVideoSource(static_cast<int>(vs));
7311
+ REPORT_FUNCTION();
7314
+ ALOGE("mr must not be NULL");
7315
+ return android::BAD_VALUE;
7318
+ return mr->setVideoSource(static_cast<int>(vs));
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
4953
7327
+int android_recorder_setAudioSource(MediaRecorderWrapper *mr, AudioSource as)
4955
+ REPORT_FUNCTION();
4958
+ ALOGE("mr must not be NULL");
4962
+ return mr->setAudioSource(static_cast<int>(as));
7329
+ REPORT_FUNCTION();
7332
+ ALOGE("mr must not be NULL");
7333
+ return android::BAD_VALUE;
7336
+ return mr->setAudioSource(static_cast<int>(as));
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
4971
7345
+int android_recorder_setOutputFormat(MediaRecorderWrapper *mr, OutputFormat of)
4973
+ REPORT_FUNCTION();
4976
+ ALOGE("mr must not be NULL");
4980
+ return mr->setOutputFormat(static_cast<int>(of));
7347
+ REPORT_FUNCTION();
7350
+ ALOGE("mr must not be NULL");
7351
+ return android::BAD_VALUE;
7354
+ return mr->setOutputFormat(static_cast<int>(of));
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
4989
7363
+int android_recorder_setVideoEncoder(MediaRecorderWrapper *mr, VideoEncoder ve)
4991
+ REPORT_FUNCTION();
4994
+ ALOGE("mr must not be NULL");
4998
+ return mr->setVideoEncoder(static_cast<int>(ve));
7365
+ REPORT_FUNCTION();
7368
+ ALOGE("mr must not be NULL");
7369
+ return android::BAD_VALUE;
7372
+ return mr->setVideoEncoder(static_cast<int>(ve));
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
5007
7381
+int android_recorder_setAudioEncoder(MediaRecorderWrapper *mr, AudioEncoder ae)
5009
+ REPORT_FUNCTION();
5012
+ ALOGE("mr must not be NULL");
5016
+ return mr->setAudioEncoder(static_cast<int>(ae));
7383
+ REPORT_FUNCTION();
7386
+ ALOGE("mr must not be NULL");
7387
+ return android::BAD_VALUE;
7390
+ return mr->setAudioEncoder(static_cast<int>(ae));
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
5025
7399
+int android_recorder_setOutputFile(MediaRecorderWrapper *mr, int fd)
5027
+ REPORT_FUNCTION();
5030
+ ALOGE("mr must not be NULL");
5034
+ return mr->setOutputFile(fd, 0, 0);
7401
+ REPORT_FUNCTION();
7404
+ ALOGE("mr must not be NULL");
7405
+ return android::BAD_VALUE;
7408
+ return mr->setOutputFile(fd, 0, 0);
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
5044
7418
+int android_recorder_setVideoSize(MediaRecorderWrapper *mr, int width, int height)
5046
+ REPORT_FUNCTION();
5049
+ ALOGE("mr must not be NULL");
5053
+ return mr->setVideoSize(width, height);
7420
+ REPORT_FUNCTION();
7423
+ ALOGE("mr must not be NULL");
7424
+ return android::BAD_VALUE;
7427
+ return mr->setVideoSize(width, height);
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
5062
7436
+int android_recorder_setVideoFrameRate(MediaRecorderWrapper *mr, int frames_per_second)
5064
+ REPORT_FUNCTION();
5067
+ ALOGE("mr must not be NULL");
5071
+ return mr->setVideoFrameRate(frames_per_second);
7438
+ REPORT_FUNCTION();
7441
+ ALOGE("mr must not be NULL");
7442
+ return android::BAD_VALUE;
7445
+ return mr->setVideoFrameRate(frames_per_second);
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
5082
+int android_recorder_setParameters(MediaRecorderWrapper *mr, const char* parameters)
7456
+int android_recorder_setParameters(MediaRecorderWrapper *mr, const char *parameters)
5084
+ REPORT_FUNCTION();
5087
+ ALOGE("mr must not be NULL");
5091
+ String8 params(parameters);
5092
+ return mr->setParameters(params);
7458
+ REPORT_FUNCTION();
7461
+ ALOGE("mr must not be NULL");
7462
+ return android::BAD_VALUE;
7465
+ android::String8 params(parameters);
7466
+ return mr->setParameters(params);
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
5101
7475
+int android_recorder_start(MediaRecorderWrapper *mr)
5103
+ REPORT_FUNCTION();
5106
+ ALOGE("mr must not be NULL");
5110
+ return mr->start();
7477
+ REPORT_FUNCTION();
7480
+ ALOGE("mr must not be NULL");
7481
+ return android::BAD_VALUE;
7484
+ return mr->start();
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
5118
7492
+int android_recorder_stop(MediaRecorderWrapper *mr)
5120
+ REPORT_FUNCTION();
5123
+ ALOGE("mr must not be NULL");
5127
+ return mr->stop();
7494
+ REPORT_FUNCTION();
7497
+ ALOGE("mr must not be NULL");
7498
+ return android::BAD_VALUE;
7501
+ return mr->stop();
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
5135
7509
+int android_recorder_prepare(MediaRecorderWrapper *mr)
5137
+ REPORT_FUNCTION();
5140
+ ALOGE("mr must not be NULL");
5144
+ return mr->prepare();
7511
+ REPORT_FUNCTION();
7514
+ ALOGE("mr must not be NULL");
7515
+ return android::BAD_VALUE;
7518
+ return mr->prepare();
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
5152
7526
+int android_recorder_reset(MediaRecorderWrapper *mr)
5154
+ REPORT_FUNCTION();
5157
+ ALOGE("mr must not be NULL");
5161
+ return mr->reset();
7528
+ REPORT_FUNCTION();
7531
+ ALOGE("mr must not be NULL");
7532
+ return android::BAD_VALUE;
7535
+ return mr->reset();
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
5169
7543
+int android_recorder_close(MediaRecorderWrapper *mr)
5171
+ REPORT_FUNCTION();
5174
+ ALOGE("mr must not be NULL");
5178
+ return mr->close();
7545
+ REPORT_FUNCTION();
7548
+ ALOGE("mr must not be NULL");
7549
+ return android::BAD_VALUE;
7552
+ return mr->close();
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
5187
7561
+int android_recorder_release(MediaRecorderWrapper *mr)
5189
+ REPORT_FUNCTION();
5192
+ ALOGE("mr must not be NULL");
5196
+ return mr->release();
7563
+ REPORT_FUNCTION();
7566
+ ALOGE("mr must not be NULL");
7567
+ return android::BAD_VALUE;
7570
+ return mr->release();
5199
7573
+++ libhybris-0.1.0+git20131207+e452e83/compat/media/surface_texture_client_hybris.cpp