Re: [FFmpeg-devel] [PATCH] Add android_capture indev

2018-02-21 Thread Michael Niedermayer
On Tue, Feb 20, 2018 at 09:44:29AM +0100, Felix Matouschek wrote:
> I rebased the patch on the current master, it does apply again.
> 
> Tested it - still works.

ok, this patch was laying around for enough weeks on the mailing list,
will be part of my next push (unless some last minute issue is found)

Thanks

[...]
-- 
Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

If you think the mosad wants you dead since a long time then you are either
wrong or dead since a long time.


signature.asc
Description: PGP signature
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH] Add android_capture indev

2018-02-20 Thread Felix Matouschek

I rebased the patch on the current master, it does apply again.

Tested it - still works.

Felix

Am 19.02.2018 20:39, schrieb Michael Niedermayer:

On Mon, Feb 19, 2018 at 08:39:56AM +0100, Felix Matouschek wrote:

Hello Michael,

do you think the patch could be merged in its current state?
It is functional, maybe I can do the cosmetic changes later.
I was a bit busy the last weeks.

Would be nice if it could get into the 3.5 / 4.0 release.


not sure if there are issues remaining but it doesnt apply
anymore

Applying: avdevice: add android_camera indev
Using index info to reconstruct a base tree...
M   Changelog
M   MAINTAINERS
M   configure
M   doc/indevs.texi
M   libavdevice/alldevices.c
M   libavdevice/version.h
Falling back to patching base and 3-way merge...
Auto-merging libavdevice/alldevices.c
CONFLICT (content): Merge conflict in libavdevice/alldevices.c
Auto-merging doc/indevs.texi
Auto-merging configure
Auto-merging MAINTAINERS
Auto-merging Changelog
CONFLICT (content): Merge conflict in Changelog
error: Failed to merge in the changes.
Patch failed at 0001 avdevice: add android_camera indev
The copy of the patch that failed is found in: .git/rebase-apply/patch
When you have resolved this problem, run "git am --continue".
If you prefer to skip this patch, run "git am --skip" instead.
To restore the original branch and stop patching, run "git am --abort".


[...]
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-develFrom 3fd6cca01f175412ee3cb2c4e435694ed3cf2bb0 Mon Sep 17 00:00:00 2001
From: Felix Matouschek 
Date: Tue, 20 Feb 2018 09:41:46 +0100
Subject: [PATCH] avdevice: add android_camera indev
To: ffmpeg-devel@ffmpeg.org

This commit adds an indev for Android devices on API level 24+ which
uses the Android NDK Camera2 API to capture video from builtin cameras

Signed-off-by: Felix Matouschek 
---
 Changelog|   1 +
 MAINTAINERS  |   1 +
 configure|   6 +
 doc/indevs.texi  |  40 ++
 libavdevice/Makefile |   1 +
 libavdevice/alldevices.c |   1 +
 libavdevice/android_camera.c | 871 +++
 libavdevice/version.h|   2 +-
 8 files changed, 922 insertions(+), 1 deletion(-)
 create mode 100644 libavdevice/android_camera.c

diff --git a/Changelog b/Changelog
index 2acdbbea30..56dedd1aea 100644
--- a/Changelog
+++ b/Changelog
@@ -39,6 +39,7 @@ version :
 - Removed the ffmenc and ffmdec muxer and demuxer
 - VideoToolbox HEVC encoder and hwaccel
 - VAAPI-accelerated ProcAmp (color balance), denoise and sharpness filters
+- Add android_camera indev
 
 
 version 3.4:
diff --git a/MAINTAINERS b/MAINTAINERS
index b691bd56ec..bf1299bdbf 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -281,6 +281,7 @@ libavdevice
 
 
   avfoundation.mThilo Borgmann
+  android_camera.c  Felix Matouschek
   decklink* Marton Balint
   dshow.c   Roger Pack (CC rogerdp...@gmail.com)
   fbdev_enc.c   Lukasz Marek
diff --git a/configure b/configure
index 013308cfa4..fa5c530abe 100755
--- a/configure
+++ b/configure
@@ -3081,6 +3081,8 @@ xmv_demuxer_select="riffdec"
 xwma_demuxer_select="riffdec"
 
 # indevs / outdevs
+android_camera_indev_deps="android camera2ndk mediandk pthreads"
+android_camera_indev_extralibs="-landroid -lcamera2ndk -lmediandk"
 alsa_indev_deps="alsa"
 alsa_outdev_deps="alsa"
 avfoundation_indev_deps="avfoundation corevideo coremedia pthreads"
@@ -5756,6 +5758,10 @@ check_lib shell32  "windows.h shellapi.h" CommandLineToArgvW   -lshell32
 check_lib wincrypt "windows.h wincrypt.h" CryptGenRandom   -ladvapi32
 check_lib psapi"windows.h psapi.h"GetProcessMemoryInfo -lpsapi
 
+check_lib android android/native_window.h ANativeWindow_acquire -landroid
+check_lib mediandk "stdint.h media/NdkImage.h" AImage_delete -lmediandk
+check_lib camera2ndk "stdbool.h stdint.h camera/NdkCameraManager.h" ACameraManager_create -lcamera2ndk
+
 enabled appkit   && check_apple_framework AppKit
 enabled audiotoolbox && check_apple_framework AudioToolbox
 enabled avfoundation && check_apple_framework AVFoundation
diff --git a/doc/indevs.texi b/doc/indevs.texi
index 0bc8e6a9b1..6951940a93 100644
--- a/doc/indevs.texi
+++ b/doc/indevs.texi
@@ -63,6 +63,46 @@ Set the number of channels. Default is 2.
 
 @end table
 
+@section android_camera
+
+Android camera input device.
+
+This input devices uses the Android Camera2 NDK API which is
+available on devices with API level 24+. The availability of
+android_camera is autodetected during configuration.
+
+This device allows capturing from all cameras on an Android device,
+which are integrated into the Camera2 NDK API.
+
+The available cameras are enumerated internally and can be 

Re: [FFmpeg-devel] [PATCH] Add android_capture indev

2018-02-19 Thread Michael Niedermayer
On Mon, Feb 19, 2018 at 08:39:56AM +0100, Felix Matouschek wrote:
> Hello Michael,
> 
> do you think the patch could be merged in its current state?
> It is functional, maybe I can do the cosmetic changes later.
> I was a bit busy the last weeks.
> 
> Would be nice if it could get into the 3.5 / 4.0 release.

not sure if there are issues remaining but it doesnt apply
anymore

Applying: avdevice: add android_camera indev
Using index info to reconstruct a base tree...
M   Changelog
M   MAINTAINERS
M   configure
M   doc/indevs.texi
M   libavdevice/alldevices.c
M   libavdevice/version.h
Falling back to patching base and 3-way merge...
Auto-merging libavdevice/alldevices.c
CONFLICT (content): Merge conflict in libavdevice/alldevices.c
Auto-merging doc/indevs.texi
Auto-merging configure
Auto-merging MAINTAINERS
Auto-merging Changelog
CONFLICT (content): Merge conflict in Changelog
error: Failed to merge in the changes.
Patch failed at 0001 avdevice: add android_camera indev
The copy of the patch that failed is found in: .git/rebase-apply/patch
When you have resolved this problem, run "git am --continue".
If you prefer to skip this patch, run "git am --skip" instead.
To restore the original branch and stop patching, run "git am --abort".


[...]
-- 
Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

Democracy is the form of government in which you can choose your dictator


signature.asc
Description: PGP signature
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH] Add android_capture indev

2018-02-18 Thread Felix Matouschek

Hello Michael,

do you think the patch could be merged in its current state?
It is functional, maybe I can do the cosmetic changes later.
I was a bit busy the last weeks.

Would be nice if it could get into the 3.5 / 4.0 release.

Felix

Am 02.01.2018 10:23, schrieb Felix Matouschek:
Am 28.12.2017 um 19:20 schrieb Michael Niedermayer 
:


+av_image_copy_to_buffer(pkt.data, pkt_buffer_size,
+(const uint8_t * const *) 
image_plane_data,

+image_linestrides, ctx->image_format,
+ctx->width, ctx->height, 32);


Is the copy needed ?
can the data not be put in a AVPacket without copy but by pointing to 
the image?

the AVPackets deallocation can be overridden to free the image


I’m not sure but I guess it could lead to problems as the AImageReader
has its own queue, which is currently limited to two images. In
general the image_available callback is processed fast enough so this
is not a problem and all AVPackets are buffered in the thread message
queue (ctx->input_queue) while the original AImage is deleted. Every
AImage is also permanently associated with the AImageReader and needs
to be deleted for the AImageReader to accept new images. I think if
doing so the input_queue and the AImageReader queue probably need the
same size.

How could I put the different pointers I get from the Android system
for each plane into the AVPacket? I’m not even sure if all planes live
in the same contiguous space of memory? How does one overwrite the
AVPacket deallocation?

Currently I’m using AImageReader_acquireLatestImage(), this should be
changed to AImageReader_acquireNextImage(), other than that it could
work.

Felix

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH] Add android_capture indev

2018-01-02 Thread Felix Matouschek


> Am 28.12.2017 um 19:20 schrieb Michael Niedermayer :
>> 
>> +av_image_copy_to_buffer(pkt.data, pkt_buffer_size,
>> +(const uint8_t * const *) image_plane_data,
>> +image_linestrides, ctx->image_format,
>> +ctx->width, ctx->height, 32);
> 
> Is the copy needed ?
> can the data not be put in a AVPacket without copy but by pointing to the 
> image?
> the AVPackets deallocation can be overridden to free the image 

I’m not sure but I guess it could lead to problems as the AImageReader has its 
own queue, which is currently limited to two images. In general the 
image_available callback is processed fast enough so this is not a problem and 
all AVPackets are buffered in the thread message queue (ctx->input_queue) while 
the original AImage is deleted. Every AImage is also permanently associated 
with the AImageReader and needs to be deleted for the AImageReader to accept 
new images. I think if doing so the input_queue and the AImageReader queue 
probably need the same size. 

How could I put the different pointers I get from the Android system for each 
plane into the AVPacket? I’m not even sure if all planes live in the same 
contiguous space of memory? How does one overwrite the AVPacket deallocation?

Currently I’m using AImageReader_acquireLatestImage(), this should be changed 
to AImageReader_acquireNextImage(), other than that it could work.

Felix

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH] Add android_capture indev

2017-12-28 Thread Michael Niedermayer
On Fri, Dec 22, 2017 at 09:36:59PM +0100, Felix Matouschek wrote:
> Am 22.12.2017 20:50, schrieb Lou Logan:
> >
> >I think you forgot to attach the patch.
> 
> Sorry, flaky mail client... attached it again.
[...]

> +static void image_available(void *context, AImageReader *reader)
> +{
> +AVFormatContext *avctx = context;
> +AndroidCameraCtx *ctx = avctx->priv_data;
> +media_status_t media_status;
> +int ret = 0;
> +
> +AImage *image;
> +int64_t image_timestamp;
> +int32_t image_linestrides[4];
> +uint8_t *image_plane_data[4];
> +int plane_data_length[4];
> +
> +AVPacket pkt;
> +int pkt_buffer_size = 0;
> +
> +media_status = AImageReader_acquireLatestImage(reader, );
> +if (media_status != AMEDIA_OK) {
> +if (media_status == AMEDIA_IMGREADER_NO_BUFFER_AVAILABLE) {
> +av_log(avctx, AV_LOG_WARNING,
> +   "An image reader frame was discarded");
> +} else {
> +av_log(avctx, AV_LOG_ERROR,
> +   "Failed to acquire latest image from image reader, error: 
> %s.\n",
> +   media_status_string(media_status));
> +ret = AVERROR_EXTERNAL;
> +}
> +goto error;
> +}
> +
> +// Silently drop frames when exit is set
> +if (atomic_load(>exit)) {
> +goto error;
> +}
> +
> +// Determine actual image format
> +if (!atomic_load(>got_image_format)) {
> +ret = get_image_format(avctx, image);
> +if (ret < 0) {
> +av_log(avctx, AV_LOG_ERROR,
> +   "Could not get image format of camera.\n");
> +goto error;
> +} else {
> +atomic_store(>got_image_format, 1);
> +}
> +}
> +
> +pkt_buffer_size = av_image_get_buffer_size(ctx->image_format, 
> ctx->width, ctx->height, 32);
> +AImage_getTimestamp(image, _timestamp);
> +
> +AImage_getPlaneRowStride(image, 0, _linestrides[0]);
> +AImage_getPlaneData(image, 0, _plane_data[0], 
> _data_length[0]);
> +
> +switch (ctx->image_format) {
> +case AV_PIX_FMT_YUV420P:
> +AImage_getPlaneRowStride(image, 1, _linestrides[1]);
> +AImage_getPlaneData(image, 1, _plane_data[1], 
> _data_length[1]);
> +AImage_getPlaneRowStride(image, 2, _linestrides[2]);
> +AImage_getPlaneData(image, 2, _plane_data[2], 
> _data_length[2]);
> +break;
> +case AV_PIX_FMT_NV12:
> +AImage_getPlaneRowStride(image, 1, _linestrides[1]);
> +AImage_getPlaneData(image, 1, _plane_data[1], 
> _data_length[1]);
> +break;
> +case AV_PIX_FMT_NV21:
> +AImage_getPlaneRowStride(image, 2, _linestrides[1]);
> +AImage_getPlaneData(image, 2, _plane_data[1], 
> _data_length[1]);
> +break;
> +default:
> +av_log(avctx, AV_LOG_ERROR, "Unsupported camera image 
> format.\n");
> +ret = AVERROR(ENOSYS);
> +goto error;
> +}
> +
> +ret = av_new_packet(, pkt_buffer_size);
> +if (ret < 0) {
> +av_log(avctx, AV_LOG_ERROR,
> +   "Failed to create new av packet, error: %s.\n", 
> av_err2str(ret));
> +goto error;
> +}
> +
> +pkt.stream_index = VIDEO_STREAM_INDEX;
> +pkt.pts = image_timestamp;
> +av_image_copy_to_buffer(pkt.data, pkt_buffer_size,
> +(const uint8_t * const *) image_plane_data,
> +image_linestrides, ctx->image_format,
> +ctx->width, ctx->height, 32);

Is the copy needed ?
can the data not be put in a AVPacket without copy but by pointing to the image?
the AVPackets deallocation can be overridden to free the image 
[...]

-- 
Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

Never trust a computer, one day, it may think you are the virus. -- Compn


signature.asc
Description: PGP signature
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH] Add android_capture indev

2017-12-27 Thread Felix Matouschek
Ping

> Am 22.12.2017 um 21:36 schrieb Felix Matouschek :
> 
> Am 22.12.2017 20:50, schrieb Lou Logan:
>> I think you forgot to attach the patch.
> 
> Sorry, flaky mail client... attached it again.
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH] Add android_capture indev

2017-12-22 Thread Felix Matouschek

Am 22.12.2017 20:50, schrieb Lou Logan:


I think you forgot to attach the patch.


Sorry, flaky mail client... attached it again.From ba2ccca1200a55b0f1c0331ebd6d26324941fb2e Mon Sep 17 00:00:00 2001
From: Felix Matouschek 
Date: Fri, 22 Dec 2017 20:10:41 +0100
Subject: [PATCH] avdevice: add android_camera indev
To: ffmpeg-devel@ffmpeg.org

This commit adds an indev for Android devices on API level 24+ which
uses the Android NDK Camera2 API to capture video from builtin cameras

Signed-off-by: Felix Matouschek 
---
 Changelog|   1 +
 MAINTAINERS  |   1 +
 configure|   6 +
 doc/indevs.texi  |  40 ++
 libavdevice/Makefile |   1 +
 libavdevice/alldevices.c |   1 +
 libavdevice/android_camera.c | 871 +++
 libavdevice/version.h|   2 +-
 8 files changed, 922 insertions(+), 1 deletion(-)
 create mode 100644 libavdevice/android_camera.c

diff --git a/Changelog b/Changelog
index ee48876128..f5e6326d32 100644
--- a/Changelog
+++ b/Changelog
@@ -27,6 +27,7 @@ version :
 - video setrange filter
 - nsp demuxer
 - support LibreSSL (via libtls)
+- Add android_camera indev
 
 
 version 3.4:
diff --git a/MAINTAINERS b/MAINTAINERS
index 6a92b5190d..bc6cbc51a6 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -282,6 +282,7 @@ libavdevice
 
 
   avfoundation.mThilo Borgmann
+  android_camera.c  Felix Matouschek
   decklink* Marton Balint
   dshow.c   Roger Pack (CC rogerdp...@gmail.com)
   fbdev_enc.c   Lukasz Marek
diff --git a/configure b/configure
index d09eec4155..b8a7d4bfed 100755
--- a/configure
+++ b/configure
@@ -3073,6 +3073,8 @@ xmv_demuxer_select="riffdec"
 xwma_demuxer_select="riffdec"
 
 # indevs / outdevs
+android_camera_indev_deps="android camera2ndk mediandk pthreads"
+android_camera_indev_extralibs="-landroid -lcamera2ndk -lmediandk"
 alsa_indev_deps="alsa"
 alsa_outdev_deps="alsa"
 avfoundation_indev_deps="avfoundation corevideo coremedia pthreads"
@@ -5707,6 +5709,10 @@ check_lib shell32  "windows.h shellapi.h" CommandLineToArgvW   -lshell32
 check_lib wincrypt "windows.h wincrypt.h" CryptGenRandom   -ladvapi32
 check_lib psapi"windows.h psapi.h"GetProcessMemoryInfo -lpsapi
 
+check_lib android android/native_window.h ANativeWindow_acquire -landroid
+check_lib mediandk "stdint.h media/NdkImage.h" AImage_delete -lmediandk
+check_lib camera2ndk "stdbool.h stdint.h camera/NdkCameraManager.h" ACameraManager_create -lcamera2ndk
+
 enabled appkit   && check_apple_framework AppKit
 enabled audiotoolbox && check_apple_framework AudioToolbox
 enabled avfoundation && check_apple_framework AVFoundation
diff --git a/doc/indevs.texi b/doc/indevs.texi
index 56066bf23a..93a671dd42 100644
--- a/doc/indevs.texi
+++ b/doc/indevs.texi
@@ -63,6 +63,46 @@ Set the number of channels. Default is 2.
 
 @end table
 
+@section android_camera
+
+Android camera input device.
+
+This input devices uses the Android Camera2 NDK API which is
+available on devices with API level 24+. The availability of
+android_camera is autodetected during configuration.
+
+This device allows capturing from all cameras on an Android device,
+which are integrated into the Camera2 NDK API.
+
+The available cameras are enumerated internally and can be selected
+with the @var{camera_index} parameter. The input file string is
+discarded.
+
+Generally the back facing camera has index 0 while the front facing
+camera has index 1.
+
+@subsection Options
+
+@table @option
+
+@item video_size
+Set the video size given as a string such as 640x480 or hd720.
+Falls back to the first available configuration reported by
+Android if requested video size is not available or by default.
+
+@item framerate
+Set the video framerate.
+Falls back to the first available configuration reported by
+Android if requested framerate is not available or by default (-1).
+
+@item camera_index
+Set the index of the camera to use. Default is 0.
+
+@item input_queue_size
+Set the maximum number of frames to buffer. Default is 5.
+
+@end table
+
 @section avfoundation
 
 AVFoundation input device.
diff --git a/libavdevice/Makefile b/libavdevice/Makefile
index 8228d62147..f11a6f2a86 100644
--- a/libavdevice/Makefile
+++ b/libavdevice/Makefile
@@ -14,6 +14,7 @@ OBJS-$(CONFIG_SHARED)+= reverse.o
 # input/output devices
 OBJS-$(CONFIG_ALSA_INDEV)+= alsa_dec.o alsa.o timefilter.o
 OBJS-$(CONFIG_ALSA_OUTDEV)   += alsa_enc.o alsa.o
+OBJS-$(CONFIG_ANDROID_CAMERA_INDEV)  += android_camera.o
 OBJS-$(CONFIG_AVFOUNDATION_INDEV)+= avfoundation.o
 OBJS-$(CONFIG_BKTR_INDEV)+= bktr.o
 OBJS-$(CONFIG_CACA_OUTDEV)   += caca.o
diff --git a/libavdevice/alldevices.c b/libavdevice/alldevices.c
index 

Re: [FFmpeg-devel] [PATCH] Add android_capture indev

2017-12-22 Thread Lou Logan
On Fri, Dec 22, 2017, at 10:34 AM, Felix Matouschek wrote:
> Hello Michael,
> 
> I fixed the things you mentioned. New patch attached.
> 
> Felix

I think you forgot to attach the patch.
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH] Add android_capture indev

2017-12-22 Thread Felix Matouschek

Hello Michael,

I fixed the things you mentioned. New patch attached.

Felix
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH] Add android_capture indev

2017-12-20 Thread Michael Niedermayer
On Fri, Dec 08, 2017 at 10:49:56AM +0100, Felix Matouschek wrote:
[...]
> +static int open_camera(AVFormatContext *avctx)
> +{
> +AndroidCameraCtx *ctx = avctx->priv_data;
> +camera_status_t ret;
> +ACameraIdList *camera_ids;
> +
> +ret = ACameraManager_getCameraIdList(ctx->camera_mgr, _ids);
> +if (ret != ACAMERA_OK) {
> +av_log(avctx, AV_LOG_ERROR, "Failed to get camera id list, error: 
> %s.\n",
> +   camera_status_string(ret));
> +return AVERROR_EXTERNAL;
> +}
> +
> +if (ctx->camera_index < camera_ids->numCameras) {

> +ctx->camera_id = av_strdup(camera_ids->cameraIds[ctx->camera_index]);

missing memory allocation failure check


> +} else {
> +av_log(avctx, AV_LOG_ERROR, "No camera with index %d available.\n",
> +   ctx->camera_index);
> +return AVERROR(ENXIO);
> +}
> +
> +ACameraManager_deleteCameraIdList(camera_ids);
> +
> +ret = ACameraManager_getCameraCharacteristics(ctx->camera_mgr,
> +ctx->camera_id, >camera_metadata);
> +if (ret != ACAMERA_OK) {
> +av_log(avctx, AV_LOG_ERROR, "Failed to get metadata for camera with 
> id %s, error: %s.\n",
> +   ctx->camera_id, camera_status_string(ret));
> +return AVERROR_EXTERNAL;
> +}
> +
> +ctx->camera_state_callbacks.context = avctx;
> +ctx->camera_state_callbacks.onDisconnected = camera_dev_disconnected;
> +ctx->camera_state_callbacks.onError = camera_dev_error;
> +
> +ret = ACameraManager_openCamera(ctx->camera_mgr, ctx->camera_id,
> +>camera_state_callbacks, 
> >camera_dev);
> +if (ret != ACAMERA_OK) {
> +av_log(avctx, AV_LOG_ERROR, "Failed to open camera with id %s, 
> error: %s.\n",
> +   ctx->camera_id, camera_status_string(ret));
> +return AVERROR_EXTERNAL;
> +}
> +
> +return 0;
> +}
> +
> +static void get_sensor_orientation(AVFormatContext *avctx)
> +{
> +AndroidCameraCtx *ctx = avctx->priv_data;
> +ACameraMetadata_const_entry lens_facing;
> +ACameraMetadata_const_entry sensor_orientation;
> +
> +ACameraMetadata_getConstEntry(ctx->camera_metadata,
> +  ACAMERA_LENS_FACING, _facing);
> +ACameraMetadata_getConstEntry(ctx->camera_metadata,
> +  ACAMERA_SENSOR_ORIENTATION, 
> _orientation);
> +
> +ctx->lens_facing = lens_facing.data.u8[0];
> +ctx->sensor_orientation = sensor_orientation.data.i32[0];
> +}
> +

> +static void match_video_size(AVFormatContext *avctx)
> +{
> +AndroidCameraCtx *ctx = avctx->priv_data;
> +ACameraMetadata_const_entry available_configs;
> +int found = 0;
> +
> +ACameraMetadata_getConstEntry(ctx->camera_metadata,
> +  
> ACAMERA_SCALER_AVAILABLE_STREAM_CONFIGURATIONS,
> +  _configs);
> +
> +for (int i = 0; i < available_configs.count; i++) {
> +int32_t input = available_configs.data.i32[i * 4 + 3];
> +int32_t format = available_configs.data.i32[i * 4 + 0];
> +
> +if (input) {
> +continue;
> +}
> +
> +if (format == IMAGE_FORMAT_ANDROID) {
> +int32_t width = available_configs.data.i32[i * 4 + 1];
> +int32_t height = available_configs.data.i32[i * 4 + 2];
> +
> +//Same ratio
> +if ((ctx->requested_width == width || ctx->requested_width == 
> height) &&
> +(ctx->requested_height == width || ctx->requested_height 
> == height)) {

with thix 100x100 would match anything that has 100 in either w or h, notg 
needing both
is this intended ?


> +ctx->width = width;
> +ctx->height = height;
> +found = 1;
> +break;
> +}
> +}
> +}
> +
> +if (!found || ctx->width == 0 || ctx->height == 0) {
> +ctx->width = available_configs.data.i32[1];
> +ctx->height = available_configs.data.i32[2];
> +
> +av_log(avctx, AV_LOG_WARNING,
> +   "Requested video_size %dx%d not available, falling back to 
> %dx%d\n",
> +   ctx->requested_width, ctx->requested_height, ctx->width, 
> ctx->height);
> +}
> +
> +return;
> +}
> +

> +static void match_framerate(AVFormatContext *avctx)
> +{
> +AndroidCameraCtx *ctx = avctx->priv_data;
> +ACameraMetadata_const_entry available_framerates;
> +int found = 0;
> +int current_best_match = -1;
> +double requested_framerate = av_q2d(ctx->framerate);

Theres no need to use a floating point value. Not using one would
avoid any risk from rounding differences

[...]

-- 
Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

"You are 36 times more likely to die in a bathtub than at the hands of a
terrorist. Also, you are 2.5 times more likely to become a president and
2 times more likely to become an astronaut, 

Re: [FFmpeg-devel] [PATCH] Add android_capture indev

2017-12-19 Thread Felix Matouschek
Hello Michael,

could you take a look at the patch?

Felix

> Am 30.11.2017 um 18:15 schrieb Michael Niedermayer :
> 
> On Thu, Nov 30, 2017 at 10:15:48AM +0100, Felix Matouschek wrote:
>> Sorry, my mail client swallowed the attachment, sent it again.
>> 
> 
>> Changelog|1 
>> MAINTAINERS  |1 
>> configure|6 
>> doc/indevs.texi  |   40 ++
>> libavdevice/Makefile |1 
>> libavdevice/alldevices.c |1 
>> libavdevice/android_camera.c |  816 
>> +++
>> libavdevice/version.h|2 
>> 8 files changed, 867 insertions(+), 1 deletion(-)
>> 2fea6cb3990aed83c3a3c492aa482f619a885ed7  
>> 0001-avdevice-add-android_camera-indev.patch
>> From b70da28e33e07b4565daffc94c8ffe3c8df747ff Mon Sep 17 00:00:00 2001
>> From: Felix Matouschek 
>> Date: Thu, 30 Nov 2017 10:03:54 +0100
>> Subject: [PATCH] avdevice: add android_camera indev
>> To: ffmpeg-devel@ffmpeg.org
>> 
>> This commit adds an indev for Android devices on API level 24+ which
>> uses the Android NDK Camera2 API to capture video from builtin cameras
>> 
>> Signed-off-by: Felix Matouschek 
>> ---
>> Changelog|   1 +
>> MAINTAINERS  |   1 +
>> configure|   6 +
>> doc/indevs.texi  |  40 +++
>> libavdevice/Makefile |   1 +
>> libavdevice/alldevices.c |   1 +
>> libavdevice/android_camera.c | 816 
>> +++
>> libavdevice/version.h|   2 +-
>> 8 files changed, 867 insertions(+), 1 deletion(-)
>> create mode 100644 libavdevice/android_camera.c
>> 
>> diff --git a/Changelog b/Changelog
>> index 6592d868da..f58cd810e0 100644
>> --- a/Changelog
>> +++ b/Changelog
>> @@ -6,6 +6,7 @@ version :
>> - Dropped support for OpenJPEG versions 2.0 and below. Using OpenJPEG now
>>   requires 2.1 (or later) and pkg-config.
>> - VDA dropped (use VideoToolbox instead)
>> +- Add android_camera indev
>> 
>> 
>> version 3.4:
>> diff --git a/MAINTAINERS b/MAINTAINERS
>> index 1d2ff78b0e..d6cb135964 100644
>> --- a/MAINTAINERS
>> +++ b/MAINTAINERS
>> @@ -281,6 +281,7 @@ libavdevice
>> 
>> 
>>   avfoundation.mThilo Borgmann
>> +  android_camera.c  Felix Matouschek
>>   decklink* Marton Balint
>>   dshow.c   Roger Pack (CC rogerdp...@gmail.com)
>>   fbdev_enc.c   Lukasz Marek
>> diff --git a/configure b/configure
>> index 7a53bc76c7..d52b18fab3 100755
>> --- a/configure
>> +++ b/configure
>> @@ -3068,6 +3068,8 @@ xmv_demuxer_select="riffdec"
>> xwma_demuxer_select="riffdec"
>> 
>> # indevs / outdevs
>> +android_camera_indev_deps="android camera2ndk mediandk pthreads"
>> +android_camera_indev_extralibs="-landroid -lcamera2ndk -lmediandk"
>> alsa_indev_deps="alsa"
>> alsa_outdev_deps="alsa"
>> avfoundation_indev_deps="avfoundation corevideo coremedia pthreads"
>> @@ -5836,6 +5838,10 @@ check_lib shell32  "windows.h shellapi.h" 
>> CommandLineToArgvW   -lshell32
>> check_lib wincrypt "windows.h wincrypt.h" CryptGenRandom   -ladvapi32
>> check_lib psapi"windows.h psapi.h"GetProcessMemoryInfo -lpsapi
>> 
>> +check_lib android android/native_window.h ANativeWindow_acquire -landroid
>> +check_lib mediandk "stdint.h media/NdkImage.h" AImage_delete -lmediandk
>> +check_lib camera2ndk "stdbool.h stdint.h camera/NdkCameraManager.h" 
>> ACameraManager_create -lcamera2ndk
>> +
>> enabled appkit   && check_apple_framework AppKit
>> enabled audiotoolbox && check_apple_framework AudioToolbox
>> enabled avfoundation && check_apple_framework AVFoundation
>> diff --git a/doc/indevs.texi b/doc/indevs.texi
>> index d308bbf7de..07056d762e 100644
>> --- a/doc/indevs.texi
>> +++ b/doc/indevs.texi
>> @@ -63,6 +63,46 @@ Set the number of channels. Default is 2.
>> 
>> @end table
>> 
>> +@section android_camera
>> +
>> +Android camera input device.
>> +
>> +This input devices uses the Android Camera2 NDK API which is
>> +available on devices with API level 24+. The availability of
>> +android_camera is autodetected during configuration.
>> +
>> +This device allows capturing from all cameras on an Android device,
>> +which are integrated into the Camera2 NDK API.
>> +
>> +The available cameras are enumerated internally and can be selected
>> +with the @var{camera_index} parameter. The input file string is
>> +discarded.
>> +
>> +Generally the back facing camera has index 0 while the front facing
>> +camera has index 1.
>> +
>> +@subsection Options
>> +
>> +@table @option
>> +
>> +@item video_size
>> +Set the video size given as a string such as 640x480 or hd720.
>> +Falls back to the first available configuration reported by
>> +Android if requested video size is not available or by default.
>> +
>> +@item framerate
>> +Set the video framerate.
>> 

Re: [FFmpeg-devel] [PATCH] Add android_capture indev

2017-12-08 Thread Felix Matouschek

Am 30.11.2017 17:40, schrieb Michael Niedermayer:

yes, if you dont set it, it will be computet but it would give some
latency on startup as it needs a few frames first to base the 
computation

on. This latency may or may not be a bigger problem than slightly
incorrect values. I dont know, its up to you i think what you feel
is more important


I tested it, it works way better when setting it manually so I will 
leave it like it is.


I've done some further fixes and adjustments to the patch, I attached 
the newest version.


It now works on Android 7 and 8 (tested on Nexus 9 and Pixel 2).From 80182b2ec0c2fc76584c71a7138c58b4716d5d5f Mon Sep 17 00:00:00 2001
From: Felix Matouschek 
Date: Fri, 8 Dec 2017 10:43:51 +0100
Subject: [PATCH] avdevice: add android_camera indev
To: ffmpeg-devel@ffmpeg.org

This commit adds an indev for Android devices on API level 24+ which
uses the Android NDK Camera2 API to capture video from builtin cameras

Signed-off-by: Felix Matouschek 
---
 Changelog|   1 +
 MAINTAINERS  |   1 +
 configure|   6 +
 doc/indevs.texi  |  40 ++
 libavdevice/Makefile |   1 +
 libavdevice/alldevices.c |   1 +
 libavdevice/android_camera.c | 866 +++
 libavdevice/version.h|   2 +-
 8 files changed, 917 insertions(+), 1 deletion(-)
 create mode 100644 libavdevice/android_camera.c

diff --git a/Changelog b/Changelog
index 6592d868da..f58cd810e0 100644
--- a/Changelog
+++ b/Changelog
@@ -6,6 +6,7 @@ version :
 - Dropped support for OpenJPEG versions 2.0 and below. Using OpenJPEG now
   requires 2.1 (or later) and pkg-config.
 - VDA dropped (use VideoToolbox instead)
+- Add android_camera indev
 
 
 version 3.4:
diff --git a/MAINTAINERS b/MAINTAINERS
index 1d2ff78b0e..d6cb135964 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -281,6 +281,7 @@ libavdevice
 
 
   avfoundation.mThilo Borgmann
+  android_camera.c  Felix Matouschek
   decklink* Marton Balint
   dshow.c   Roger Pack (CC rogerdp...@gmail.com)
   fbdev_enc.c   Lukasz Marek
diff --git a/configure b/configure
index 7a53bc76c7..d52b18fab3 100755
--- a/configure
+++ b/configure
@@ -3068,6 +3068,8 @@ xmv_demuxer_select="riffdec"
 xwma_demuxer_select="riffdec"
 
 # indevs / outdevs
+android_camera_indev_deps="android camera2ndk mediandk pthreads"
+android_camera_indev_extralibs="-landroid -lcamera2ndk -lmediandk"
 alsa_indev_deps="alsa"
 alsa_outdev_deps="alsa"
 avfoundation_indev_deps="avfoundation corevideo coremedia pthreads"
@@ -5836,6 +5838,10 @@ check_lib shell32  "windows.h shellapi.h" CommandLineToArgvW   -lshell32
 check_lib wincrypt "windows.h wincrypt.h" CryptGenRandom   -ladvapi32
 check_lib psapi"windows.h psapi.h"GetProcessMemoryInfo -lpsapi
 
+check_lib android android/native_window.h ANativeWindow_acquire -landroid
+check_lib mediandk "stdint.h media/NdkImage.h" AImage_delete -lmediandk
+check_lib camera2ndk "stdbool.h stdint.h camera/NdkCameraManager.h" ACameraManager_create -lcamera2ndk
+
 enabled appkit   && check_apple_framework AppKit
 enabled audiotoolbox && check_apple_framework AudioToolbox
 enabled avfoundation && check_apple_framework AVFoundation
diff --git a/doc/indevs.texi b/doc/indevs.texi
index d308bbf7de..07056d762e 100644
--- a/doc/indevs.texi
+++ b/doc/indevs.texi
@@ -63,6 +63,46 @@ Set the number of channels. Default is 2.
 
 @end table
 
+@section android_camera
+
+Android camera input device.
+
+This input devices uses the Android Camera2 NDK API which is
+available on devices with API level 24+. The availability of
+android_camera is autodetected during configuration.
+
+This device allows capturing from all cameras on an Android device,
+which are integrated into the Camera2 NDK API.
+
+The available cameras are enumerated internally and can be selected
+with the @var{camera_index} parameter. The input file string is
+discarded.
+
+Generally the back facing camera has index 0 while the front facing
+camera has index 1.
+
+@subsection Options
+
+@table @option
+
+@item video_size
+Set the video size given as a string such as 640x480 or hd720.
+Falls back to the first available configuration reported by
+Android if requested video size is not available or by default.
+
+@item framerate
+Set the video framerate.
+Falls back to the first available configuration reported by
+Android if requested framerate is not available or by default (-1).
+
+@item camera_index
+Set the index of the camera to use. Default is 0.
+
+@item input_queue_size
+Set the maximum number of frames to buffer. Default is 5.
+
+@end table
+
 @section avfoundation
 
 AVFoundation input device.
diff --git a/libavdevice/Makefile b/libavdevice/Makefile
index 8228d62147..f11a6f2a86 100644
--- a/libavdevice/Makefile
+++ b/libavdevice/Makefile

Re: [FFmpeg-devel] [PATCH] Add android_capture indev

2017-11-30 Thread Michael Niedermayer
On Thu, Nov 30, 2017 at 10:15:48AM +0100, Felix Matouschek wrote:
> Sorry, my mail client swallowed the attachment, sent it again.
> 

>  Changelog|1 
>  MAINTAINERS  |1 
>  configure|6 
>  doc/indevs.texi  |   40 ++
>  libavdevice/Makefile |1 
>  libavdevice/alldevices.c |1 
>  libavdevice/android_camera.c |  816 
> +++
>  libavdevice/version.h|2 
>  8 files changed, 867 insertions(+), 1 deletion(-)
> 2fea6cb3990aed83c3a3c492aa482f619a885ed7  
> 0001-avdevice-add-android_camera-indev.patch
> From b70da28e33e07b4565daffc94c8ffe3c8df747ff Mon Sep 17 00:00:00 2001
> From: Felix Matouschek 
> Date: Thu, 30 Nov 2017 10:03:54 +0100
> Subject: [PATCH] avdevice: add android_camera indev
> To: ffmpeg-devel@ffmpeg.org
> 
> This commit adds an indev for Android devices on API level 24+ which
> uses the Android NDK Camera2 API to capture video from builtin cameras
> 
> Signed-off-by: Felix Matouschek 
> ---
>  Changelog|   1 +
>  MAINTAINERS  |   1 +
>  configure|   6 +
>  doc/indevs.texi  |  40 +++
>  libavdevice/Makefile |   1 +
>  libavdevice/alldevices.c |   1 +
>  libavdevice/android_camera.c | 816 
> +++
>  libavdevice/version.h|   2 +-
>  8 files changed, 867 insertions(+), 1 deletion(-)
>  create mode 100644 libavdevice/android_camera.c
> 
> diff --git a/Changelog b/Changelog
> index 6592d868da..f58cd810e0 100644
> --- a/Changelog
> +++ b/Changelog
> @@ -6,6 +6,7 @@ version :
>  - Dropped support for OpenJPEG versions 2.0 and below. Using OpenJPEG now
>requires 2.1 (or later) and pkg-config.
>  - VDA dropped (use VideoToolbox instead)
> +- Add android_camera indev
>  
>  
>  version 3.4:
> diff --git a/MAINTAINERS b/MAINTAINERS
> index 1d2ff78b0e..d6cb135964 100644
> --- a/MAINTAINERS
> +++ b/MAINTAINERS
> @@ -281,6 +281,7 @@ libavdevice
>  
>  
>avfoundation.mThilo Borgmann
> +  android_camera.c  Felix Matouschek
>decklink* Marton Balint
>dshow.c   Roger Pack (CC rogerdp...@gmail.com)
>fbdev_enc.c   Lukasz Marek
> diff --git a/configure b/configure
> index 7a53bc76c7..d52b18fab3 100755
> --- a/configure
> +++ b/configure
> @@ -3068,6 +3068,8 @@ xmv_demuxer_select="riffdec"
>  xwma_demuxer_select="riffdec"
>  
>  # indevs / outdevs
> +android_camera_indev_deps="android camera2ndk mediandk pthreads"
> +android_camera_indev_extralibs="-landroid -lcamera2ndk -lmediandk"
>  alsa_indev_deps="alsa"
>  alsa_outdev_deps="alsa"
>  avfoundation_indev_deps="avfoundation corevideo coremedia pthreads"
> @@ -5836,6 +5838,10 @@ check_lib shell32  "windows.h shellapi.h" 
> CommandLineToArgvW   -lshell32
>  check_lib wincrypt "windows.h wincrypt.h" CryptGenRandom   -ladvapi32
>  check_lib psapi"windows.h psapi.h"GetProcessMemoryInfo -lpsapi
>  
> +check_lib android android/native_window.h ANativeWindow_acquire -landroid
> +check_lib mediandk "stdint.h media/NdkImage.h" AImage_delete -lmediandk
> +check_lib camera2ndk "stdbool.h stdint.h camera/NdkCameraManager.h" 
> ACameraManager_create -lcamera2ndk
> +
>  enabled appkit   && check_apple_framework AppKit
>  enabled audiotoolbox && check_apple_framework AudioToolbox
>  enabled avfoundation && check_apple_framework AVFoundation
> diff --git a/doc/indevs.texi b/doc/indevs.texi
> index d308bbf7de..07056d762e 100644
> --- a/doc/indevs.texi
> +++ b/doc/indevs.texi
> @@ -63,6 +63,46 @@ Set the number of channels. Default is 2.
>  
>  @end table
>  
> +@section android_camera
> +
> +Android camera input device.
> +
> +This input devices uses the Android Camera2 NDK API which is
> +available on devices with API level 24+. The availability of
> +android_camera is autodetected during configuration.
> +
> +This device allows capturing from all cameras on an Android device,
> +which are integrated into the Camera2 NDK API.
> +
> +The available cameras are enumerated internally and can be selected
> +with the @var{camera_index} parameter. The input file string is
> +discarded.
> +
> +Generally the back facing camera has index 0 while the front facing
> +camera has index 1.
> +
> +@subsection Options
> +
> +@table @option
> +
> +@item video_size
> +Set the video size given as a string such as 640x480 or hd720.
> +Falls back to the first available configuration reported by
> +Android if requested video size is not available or by default.
> +
> +@item framerate
> +Set the video framerate.
> +Falls back to the first available configuration reported by
> +Android if requested framerate is not available or by default (-1).
> +
> +@item camera_index
> +Set the index of the camera to use. Default is 0.
> +
> +@item 

Re: [FFmpeg-devel] [PATCH] Add android_capture indev

2017-11-30 Thread Michael Niedermayer
On Thu, Nov 30, 2017 at 05:29:45PM +0100, Felix Matouschek wrote:
> Am 30.11.2017 14:48, schrieb Michael Niedermayer:
> >>You mean avg_frame_rate and r_frame_rate?
> >>The framerate can vary between the values in framerate_range[0]
> >>(min) and framerate_range[1] (max).
> >>Ideally both values are the same, sometimes min can be lower but for
> >>the average the framerate should be what is in max.
> >>Should I set r_frame_rate to min?
> >
> >I think if you do not know the base or average frame rate you
> >should not set it.
> >Or does this lead to some unreasonable latency ?
> >or are the computed values worse ?
> 
> On some devices min and max are the same so the framerate is fixed
> and I know it.
> On other devices the min framerate can be lower and so the actual
> framerate can vary between both values.
> 
> On average the framerate still should be around the maximum value.
> 

> Do you think I'm better off not setting it at all? Will it then get
> computed automatically?

yes, if you dont set it, it will be computet but it would give some
latency on startup as it needs a few frames first to base the computation
on. This latency may or may not be a bigger problem than slightly
incorrect values. I dont know, its up to you i think what you feel
is more important

[...]
-- 
Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

It is dangerous to be right in matters on which the established authorities
are wrong. -- Voltaire


signature.asc
Description: Digital signature
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH] Add android_capture indev

2017-11-30 Thread Felix Matouschek

Am 30.11.2017 14:48, schrieb Michael Niedermayer:

You mean avg_frame_rate and r_frame_rate?
The framerate can vary between the values in framerate_range[0]
(min) and framerate_range[1] (max).
Ideally both values are the same, sometimes min can be lower but for
the average the framerate should be what is in max.
Should I set r_frame_rate to min?


I think if you do not know the base or average frame rate you
should not set it.
Or does this lead to some unreasonable latency ?
or are the computed values worse ?


On some devices min and max are the same so the framerate is fixed and I 
know it.
On other devices the min framerate can be lower and so the actual 
framerate can vary between both values.


On average the framerate still should be around the maximum value.

Do you think I'm better off not setting it at all? Will it then get 
computed automatically?

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH] Add android_capture indev

2017-11-30 Thread Michael Niedermayer
On Thu, Nov 30, 2017 at 10:12:53AM +0100, Felix Matouschek wrote:
> Am 29.11.2017 04:31, schrieb Michael Niedermayer:
> 
> >if the identifer and the string always match you could do this
> >with a macro avoiding the neede to duplcate each string
> >see AV_STRINGIFY
> 
> I changed it, is it ok like this?
> 
> >[...]
> >>+static int add_video_stream(AVFormatContext *avctx)
> >>+{
> >>+AndroidCameraCtx *ctx = avctx->priv_data;
> >>+AVStream *st;
> >>+AVCodecParameters *codecpar;
> >>+
> >>+st = avformat_new_stream(avctx, NULL);
> >>+if (!st) {
> >>+return AVERROR(ENOMEM);
> >>+}
> >>+
> >>+st->id = VIDEO_STREAM_INDEX;
> >
> >>+st->avg_frame_rate = (AVRational) { ctx->framerate_range[1], 1 };
> >>+st->r_frame_rate = (AVRational) { ctx->framerate_range[1], 1 };
> >
> >Are these values always correct ?
> 
> You mean avg_frame_rate and r_frame_rate?
> The framerate can vary between the values in framerate_range[0]
> (min) and framerate_range[1] (max).
> Ideally both values are the same, sometimes min can be lower but for
> the average the framerate should be what is in max.
> Should I set r_frame_rate to min?

I think if you do not know the base or average frame rate you
should not set it.
Or does this lead to some unreasonable latency ?
or are the computed values worse ?


> 
> I fixed all other parts you mentioned.
> 
> Felix
> ___
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> http://ffmpeg.org/mailman/listinfo/ffmpeg-devel

-- 
Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

If you drop bombs on a foreign country and kill a hundred thousand
innocent people, expect your government to call the consequence
"unprovoked inhuman terrorist attacks" and use it to justify dropping
more bombs and killing more people. The technology changed, the idea is old.


signature.asc
Description: Digital signature
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH] Add android_capture indev

2017-11-30 Thread Felix Matouschek
Sorry, my mail client swallowed the attachment, sent it again.



0001-avdevice-add-android_camera-indev.patch
Description: Binary data


> Am 30.11.2017 um 10:12 schrieb Felix Matouschek :
> 
> Am 29.11.2017 04:31, schrieb Michael Niedermayer:
> 
>> if the identifer and the string always match you could do this
>> with a macro avoiding the neede to duplcate each string
>> see AV_STRINGIFY
> 
> I changed it, is it ok like this?
> 
>> [...]
>>> +static int add_video_stream(AVFormatContext *avctx)
>>> +{
>>> +AndroidCameraCtx *ctx = avctx->priv_data;
>>> +AVStream *st;
>>> +AVCodecParameters *codecpar;
>>> +
>>> +st = avformat_new_stream(avctx, NULL);
>>> +if (!st) {
>>> +return AVERROR(ENOMEM);
>>> +}
>>> +
>>> +st->id = VIDEO_STREAM_INDEX;
>>> +st->avg_frame_rate = (AVRational) { ctx->framerate_range[1], 1 };
>>> +st->r_frame_rate = (AVRational) { ctx->framerate_range[1], 1 };
>> Are these values always correct ?
> 
> You mean avg_frame_rate and r_frame_rate?
> The framerate can vary between the values in framerate_range[0] (min) and 
> framerate_range[1] (max).
> Ideally both values are the same, sometimes min can be lower but for the 
> average the framerate should be what is in max.
> Should I set r_frame_rate to min?
> 
> I fixed all other parts you mentioned.
> 
> Felix
> ___
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH] Add android_capture indev

2017-11-30 Thread Felix Matouschek

Am 29.11.2017 04:31, schrieb Michael Niedermayer:


if the identifer and the string always match you could do this
with a macro avoiding the neede to duplcate each string
see AV_STRINGIFY


I changed it, is it ok like this?


[...]

+static int add_video_stream(AVFormatContext *avctx)
+{
+AndroidCameraCtx *ctx = avctx->priv_data;
+AVStream *st;
+AVCodecParameters *codecpar;
+
+st = avformat_new_stream(avctx, NULL);
+if (!st) {
+return AVERROR(ENOMEM);
+}
+
+st->id = VIDEO_STREAM_INDEX;



+st->avg_frame_rate = (AVRational) { ctx->framerate_range[1], 1 };
+st->r_frame_rate = (AVRational) { ctx->framerate_range[1], 1 };


Are these values always correct ?


You mean avg_frame_rate and r_frame_rate?
The framerate can vary between the values in framerate_range[0] (min) 
and framerate_range[1] (max).
Ideally both values are the same, sometimes min can be lower but for the 
average the framerate should be what is in max.

Should I set r_frame_rate to min?

I fixed all other parts you mentioned.

Felix
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH] Add android_capture indev

2017-11-28 Thread Michael Niedermayer
On Fri, Nov 10, 2017 at 09:41:04PM +0100, Felix Matouschek wrote:
> Hello,
> 
> here is a new version of the patch with further fixes.
[...]

> +static const char *camera_status_string(camera_status_t val)
> +{
> +switch(val) {
> +case ACAMERA_OK:
> +return "ACAMERA_OK";

if the identifer and the string always match you could do this
with a macro avoiding the neede to duplcate each string
see AV_STRINGIFY


[...]
> +static int read_closing(AndroidCameraCtx *ctx)
> +{
> +int read_closing;
> +pthread_mutex_lock(>read_closing_mutex);
> +read_closing = ctx->read_closing;
> +pthread_mutex_unlock(>read_closing_mutex);
> +return read_closing;
> +}
> +
> +static void set_read_closing(AndroidCameraCtx *ctx, int read_closing)
> +{
> +pthread_mutex_lock(>read_closing_mutex);
> +ctx->read_closing = read_closing;
> +pthread_mutex_unlock(>read_closing_mutex);
> +}

Thic can be simplified using C11 atomics


[...]
> +static void match_video_size(AVFormatContext *avctx)
> +{
> +AndroidCameraCtx *ctx = avctx->priv_data;
> +ACameraMetadata_const_entry available_configs;
> +int ret = -1;
> +
> +ACameraMetadata_getConstEntry(ctx->camera_metadata,
> +  
> ACAMERA_SCALER_AVAILABLE_STREAM_CONFIGURATIONS,
> +  _configs);
> +
> +for (int i = 0; i < available_configs.count; i++) {
> +int32_t input = available_configs.data.i32[i * 4 + 3];
> +int32_t format = available_configs.data.i32[i * 4 + 0];
> +
> +if (input) {
> +continue;
> +}
> +
> +if (format == IMAGE_FORMAT_ANDROID) {
> +int32_t width = available_configs.data.i32[i * 4 + 1];
> +int32_t height = available_configs.data.i32[i * 4 + 2];
> +
> +//Same ratio

> +if (ctx->requested_width * ctx->requested_height == width * 
> height) {

the product of these can maybe overflow i think


> +ctx->width = width;
> +ctx->height = height;
> +ret = 0;
> +break;
> +}
> +}
> +}
> +

> +if (ret < 0 || ctx->width == 0 || ctx->height == 0) {
> +ctx->width = available_configs.data.i32[1];
> +ctx->height = available_configs.data.i32[2];
> +ret = -1;
> +
> +av_log(avctx, AV_LOG_WARNING,
> +   "Requested video_size %dx%d not available, falling back to 
> %dx%d\n",
> +   ctx->requested_width, ctx->requested_height, ctx->width, 
> ctx->height);
> +}

you set ret but nothing uses it

> +
> +return;
> +}

[...]
> +static int add_video_stream(AVFormatContext *avctx)
> +{
> +AndroidCameraCtx *ctx = avctx->priv_data;
> +AVStream *st;
> +AVCodecParameters *codecpar;
> +
> +st = avformat_new_stream(avctx, NULL);
> +if (!st) {
> +return AVERROR(ENOMEM);
> +}
> +
> +st->id = VIDEO_STREAM_INDEX;

> +st->avg_frame_rate = (AVRational) { ctx->framerate_range[1], 1 };
> +st->r_frame_rate = (AVRational) { ctx->framerate_range[1], 1 };

Are these values always correct ?


[...]
> +if (ctx->camera_id) {
> +av_freep(>camera_id);
> +}

the if() is unneeded


[...]
-- 
Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

In a rich man's house there is no place to spit but his face.
-- Diogenes of Sinope


signature.asc
Description: Digital signature
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH] Add android_capture indev

2017-11-28 Thread Felix Matouschek

Sorry... tested it again, it does not break the default compilation.

The library check in the configure script just fails and the indev is 
not included when using the broken NDK.

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH] Add android_capture indev

2017-11-28 Thread Felix Matouschek

Am 28.11.2017 14:01, schrieb Carl Eugen Hoyos:


The patch breaks default compilation for Android?


Actually... you are right, it does.
It's a bit unfortunate as the header file in the NDK is broken.

We can't work around that in ffmpeg, the NDK needs to be fixed.
As soon as you include NdkCameraManager.h even to official examples fail 
to build.

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH] Add android_capture indev

2017-11-28 Thread Carl Eugen Hoyos
2017-11-28 8:50 GMT+01:00 Felix Matouschek :

> One last note if you try to build it yourself:
> Your NDK needs to have the patch in commit be9b8bc of this
> issue https://github.com/android-ndk/ndk/issues/559 applied.

Sorry if I misunderstand:
The patch breaks default compilation for Android?

Carl Eugen
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH] Add android_capture indev

2017-11-27 Thread Felix Matouschek

Am 22.11.2017 00:20, schrieb Michael Niedermayer:

On Tue, Nov 21, 2017 at 08:16:08AM +0100, Felix Matouschek wrote:

No more interest?


If you hear no more comments for another week, then please ping this
with CC to me and ill take a look and apply unless i spot some major
issue

also you probably want to add yourself to the MAINTAINER file if you
intend to maintain the code


Hello Michael,

as you suggested: Ping.

I added myself to the MAINTAINERS file.

One last note if you try to build it yourself:
Your NDK needs to have the patch in commit be9b8bc of this
issue https://github.com/android-ndk/ndk/issues/559 applied.

As of NDK R17 this patch will probably be included in the NDK release.

Greetings,
Felix
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH] Add android_capture indev

2017-11-21 Thread Michael Niedermayer
On Tue, Nov 21, 2017 at 08:16:08AM +0100, Felix Matouschek wrote:
> No more interest?

If you hear no more comments for another week, then please ping this
with CC to me and ill take a look and apply unless i spot some major
issue

also you probably want to add yourself to the MAINTAINER file if you
intend to maintain the code

thanks

[...]
-- 
Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

Breaking DRM is a little like attempting to break through a door even
though the window is wide open and the only thing in the house is a bunch
of things you dont want and which you would get tomorrow for free anyway


signature.asc
Description: Digital signature
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH] Add android_capture indev

2017-11-20 Thread Felix Matouschek

No more interest?

Am 02.11.2017 13:42, schrieb Felix Matouschek:

Hello,

I've written an indev for Android devices to allow capturing their
builtin cameras.
What needs to be done to merge this?

Greetings,
Felix
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH] Add android_capture indev

2017-11-13 Thread Felix Matouschek

Ping
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH] Add android_capture indev

2017-11-10 Thread Felix Matouschek
Hello,

here is a new version of the patch with further fixes.

Greetings,
Felix



0001-avdevice-add-android_camera-indev.patch
Description: Binary data


___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH] Add android_capture indev

2017-11-07 Thread Daniel Kučera
2017-11-07 18:47 GMT+01:00 Felix Matouschek :
>
>> Am 07.11.2017 um 16:17 schrieb Daniel Kučera :
>>
>> It's used like here:
>> https://github.com/danielkucera/ZidoStreamer/blob/master/app/src/main/java/eu/danman/zidostreamer/zidostreamer/StreamService.java#L62
>>
>> If I open standard streaming or camera app, no camera is listed.
>
> Note that your application uses the Camera Java API, this indev uses the 
> Camera2 NDK API.
>

You are probably right. My device has Android 4.4.2 only without any
hope for update so it won't work anyway.


-- 

S pozdravom / Best regards
Daniel Kucera.
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH] Add android_capture indev

2017-11-07 Thread Felix Matouschek

> Am 07.11.2017 um 16:17 schrieb Daniel Kučera :
> 
> It's used like here:
> https://github.com/danielkucera/ZidoStreamer/blob/master/app/src/main/java/eu/danman/zidostreamer/zidostreamer/StreamService.java#L62
> 
> If I open standard streaming or camera app, no camera is listed.

Note that your application uses the Camera Java API, this indev uses the 
Camera2 NDK API.

I think this cannot be compared directly. Could you test it in your specific 
case, whether the camera is somehow available through the NDK? Please note that 
the Camera2 NDK API only works on devices with API Level 24+ (Android 7.0).

As far as I have seen the camera in your device must also specifically support 
the Camera2 API. Cameras that are designed for the old API are only available 
in the Java version of the Camera2 API. 

You can check this in Java with: 
https://developer.android.com/reference/android/hardware/camera2/CameraCharacteristics.html#INFO_SUPPORTED_HARDWARE_LEVEL

The NDK version only supports cameras that are on the hardware level LIMITED or 
above.

Greetings,
Felix

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH] Add android_capture indev

2017-11-07 Thread Daniel Kučera
2017-11-07 15:25 GMT+01:00 Felix Matouschek :
> Am 02.11.2017 16:20, schrieb Daniel Kučera:
>
>> some devices have cameras which are unlisted - this condition makes
>> them unusable.
>
>
> How does one use unlisted devices? As far as I understood all supported
> devices are listed. If the Camera2 API does not support the camera
> it cannot be used.
>
> ___
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> http://ffmpeg.org/mailman/listinfo/ffmpeg-devel

It's used like here:
https://github.com/danielkucera/ZidoStreamer/blob/master/app/src/main/java/eu/danman/zidostreamer/zidostreamer/StreamService.java#L62

If I open standard streaming or camera app, no camera is listed.

-- 

S pozdravom / Best regards
Daniel Kucera.
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH] Add android_capture indev

2017-11-07 Thread Felix Matouschek

Am 02.11.2017 16:20, schrieb Daniel Kučera:


some devices have cameras which are unlisted - this condition makes
them unusable.


How does one use unlisted devices? As far as I understood all supported
devices are listed. If the Camera2 API does not support the camera
it cannot be used.
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH] Add android_capture indev

2017-11-07 Thread Felix Matouschek

Hello,

I tried to address all issues.
I did not have time yet to try more image formats, so it is still only 
YUV420P.


Please review.

Greetings,
FelixFrom a235f56518fc1f11698a5028dfd4b654989993c5 Mon Sep 17 00:00:00 2001
From: Felix Matouschek 
Date: Tue, 24 Oct 2017 13:11:23 +0200
Subject: [PATCH] avdevice: add android_camera indev
To: ffmpeg-devel@ffmpeg.org

This commit adds an indev for Android devices on API level 24+ which
uses the Android NDK Camera2 API to capture video from builtin cameras

Signed-off-by: Felix Matouschek 
---
 Changelog|   1 +
 configure|   6 +
 doc/indevs.texi  |  40 ++
 libavdevice/Makefile |   1 +
 libavdevice/alldevices.c |   1 +
 libavdevice/android_camera.c | 848 +++
 libavdevice/version.h|   2 +-
 7 files changed, 898 insertions(+), 1 deletion(-)
 create mode 100644 libavdevice/android_camera.c

diff --git a/Changelog b/Changelog
index 6592d868da..f58cd810e0 100644
--- a/Changelog
+++ b/Changelog
@@ -6,6 +6,7 @@ version :
 - Dropped support for OpenJPEG versions 2.0 and below. Using OpenJPEG now
   requires 2.1 (or later) and pkg-config.
 - VDA dropped (use VideoToolbox instead)
+- Add android_camera indev
 
 
 version 3.4:
diff --git a/configure b/configure
index 7a53bc76c7..d52b18fab3 100755
--- a/configure
+++ b/configure
@@ -3068,6 +3068,8 @@ xmv_demuxer_select="riffdec"
 xwma_demuxer_select="riffdec"
 
 # indevs / outdevs
+android_camera_indev_deps="android camera2ndk mediandk pthreads"
+android_camera_indev_extralibs="-landroid -lcamera2ndk -lmediandk"
 alsa_indev_deps="alsa"
 alsa_outdev_deps="alsa"
 avfoundation_indev_deps="avfoundation corevideo coremedia pthreads"
@@ -5836,6 +5838,10 @@ check_lib shell32  "windows.h shellapi.h" CommandLineToArgvW   -lshell32
 check_lib wincrypt "windows.h wincrypt.h" CryptGenRandom   -ladvapi32
 check_lib psapi"windows.h psapi.h"GetProcessMemoryInfo -lpsapi
 
+check_lib android android/native_window.h ANativeWindow_acquire -landroid
+check_lib mediandk "stdint.h media/NdkImage.h" AImage_delete -lmediandk
+check_lib camera2ndk "stdbool.h stdint.h camera/NdkCameraManager.h" ACameraManager_create -lcamera2ndk
+
 enabled appkit   && check_apple_framework AppKit
 enabled audiotoolbox && check_apple_framework AudioToolbox
 enabled avfoundation && check_apple_framework AVFoundation
diff --git a/doc/indevs.texi b/doc/indevs.texi
index d308bbf7de..07056d762e 100644
--- a/doc/indevs.texi
+++ b/doc/indevs.texi
@@ -63,6 +63,46 @@ Set the number of channels. Default is 2.
 
 @end table
 
+@section android_camera
+
+Android camera input device.
+
+This input devices uses the Android Camera2 NDK API which is
+available on devices with API level 24+. The availability of
+android_camera is autodetected during configuration.
+
+This device allows capturing from all cameras on an Android device,
+which are integrated into the Camera2 NDK API.
+
+The available cameras are enumerated internally and can be selected
+with the @var{camera_index} parameter. The input file string is
+discarded.
+
+Generally the back facing camera has index 0 while the front facing
+camera has index 1.
+
+@subsection Options
+
+@table @option
+
+@item video_size
+Set the video size given as a string such as 640x480 or hd720.
+Falls back to the first available configuration reported by
+Android if requested video size is not available or by default.
+
+@item framerate
+Set the video framerate.
+Falls back to the first available configuration reported by
+Android if requested framerate is not available or by default (-1).
+
+@item camera_index
+Set the index of the camera to use. Default is 0.
+
+@item input_queue_size
+Set the maximum number of frames to buffer. Default is 5.
+
+@end table
+
 @section avfoundation
 
 AVFoundation input device.
diff --git a/libavdevice/Makefile b/libavdevice/Makefile
index 8228d62147..f11a6f2a86 100644
--- a/libavdevice/Makefile
+++ b/libavdevice/Makefile
@@ -14,6 +14,7 @@ OBJS-$(CONFIG_SHARED)+= reverse.o
 # input/output devices
 OBJS-$(CONFIG_ALSA_INDEV)+= alsa_dec.o alsa.o timefilter.o
 OBJS-$(CONFIG_ALSA_OUTDEV)   += alsa_enc.o alsa.o
+OBJS-$(CONFIG_ANDROID_CAMERA_INDEV)  += android_camera.o
 OBJS-$(CONFIG_AVFOUNDATION_INDEV)+= avfoundation.o
 OBJS-$(CONFIG_BKTR_INDEV)+= bktr.o
 OBJS-$(CONFIG_CACA_OUTDEV)   += caca.o
diff --git a/libavdevice/alldevices.c b/libavdevice/alldevices.c
index b767b6a718..2c8d9035da 100644
--- a/libavdevice/alldevices.c
+++ b/libavdevice/alldevices.c
@@ -42,6 +42,7 @@ static void register_all(void)
 {
 /* devices */
 REGISTER_INOUTDEV(ALSA, alsa);
+REGISTER_INDEV   (ANDROID_CAMERA,   android_camera);
 REGISTER_INDEV   (AVFOUNDATION, avfoundation);
 REGISTER_INDEV   (BKTR, bktr);
 REGISTER_OUTDEV  

Re: [FFmpeg-devel] [PATCH] Add android_capture indev

2017-11-03 Thread Carl Eugen Hoyos
2017-11-03 16:21 GMT+01:00 Felix Matouschek :

>>> +if (format == IMAGE_FORMAT_ANDROID) {
>>
>> It would be better to support as many pixel formats as possible.
>
> For now I settled on YUV420P, as the API doc states all
> devices must support it. I do not have the resources to
> test every format.

You could add those that you can test (but yuv420p is of
course a very useful start).

Carl Eugen
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH] Add android_capture indev

2017-11-03 Thread Felix Matouschek

Hello,

Am 02.11.2017 um 14:40 schrieb Nicolas George:

When reading the subject of the mail, I first thought it would be about
screen capture. Furthermore, there is code for audio, but it is not
connected to anything, and it does not seem that the android API
connects audio and video together.

For all these reasons, I suggest you name this device maybe
android_camera, and keep android_mic for audio capture.

Will do so.


You are parsing the "filename" of the device into a key=value syntax.
This is not a good idea, and I really would not like another key=value
parser in the code base.

How do cameraIds look? If the string values are friendly enough, they
can be used as filenames as is.
I removed parsing of the "filename" and replaced it with a 
"camera_index" parameter.


I do not know how cameraIds are formed on different devices, seems like 
internal cameras
just use numbers but external devices may use a string. I do not have 
multiple devices to test
this. In my opionion an index for the list of all cameras should be 
sufficient.



Can the error be translated into a human-readable message?

Will try to do that, I need to add the according strings for it somehow.


Is it really the official way of getting the resolution and format of
the video? If so, were the Android people drunk?

Seem like it.


+if (format == IMAGE_FORMAT_ANDROID) {

It would be better to support as many pixel formats as possible.
For now I settled on YUV420P, as the API doc states all devices must 
support it. I do not

have the resources to test every format.


+side_data = av_packet_new_side_data(_next->pkt,
+AV_PKT_DATA_DISPLAYMATRIX, sizeof(display_matrix));

It would probably be best to avoid sending the side data repeatedly if
it does not change.
Is it sufficient to append the matrix just once? I thought every 
AVPacket could have a different matrix.



+error:
+pthread_mutex_unlock(>mutex);
+AImage_delete(image);
+
+return;

It seems error conditions are not taken into account. Is it on purpose?
You mean for example ENOMEM if allocating fails and aborting the whole 
"session"? Could do that.


Regards, 


I working on addressing all issues.

Greetings,
Felix

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH] Add android_capture indev

2017-11-02 Thread Thomas Volkert
On 02.11.2017 16:20, Daniel Kučera wrote:
> 2017-11-02 13:42 GMT+01:00 Felix Matouschek :
>> Hello,
>>
>> I've written an indev for Android devices to allow capturing their builtin
>> cameras.
>> What needs to be done to merge this?
>>
>> Greetings,
>> Felix
>> ___
>> ffmpeg-devel mailing list
>> ffmpeg-devel@ffmpeg.org
>> http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>>
> Looking forrward to this to be included. 

+ 1

Best regards,
Thomas.

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH] Add android_capture indev

2017-11-02 Thread Daniel Kučera
2017-11-02 13:42 GMT+01:00 Felix Matouschek :
> Hello,
>
> I've written an indev for Android devices to allow capturing their builtin
> cameras.
> What needs to be done to merge this?
>
> Greetings,
> Felix
> ___
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>

Looking forrward to this to be included. Just one note:

+if (ctx->video_device_number < camera_ids->numCameras) {
+ctx->camera_id = av_strdup(
+camera_ids->cameraIds[ctx->video_device_number]);
+} else {
+av_log(avctx, AV_LOG_ERROR, "No camera with number %d available.\n",
+ctx->video_device_number);
+return AVERROR(ENXIO);
+}

some devices have cameras which are unlisted - this condition makes
them unusable.


-- 

S pozdravom / Best regards
Daniel Kucera.
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH] Add android_capture indev

2017-11-02 Thread Moritz Barsnick
In addition to Nicolas's, further (style) comments:

> Subject: [PATCH] Add android_capture indev
More like:
avdevice: add android_capture [or android_camera] indev

>  configure |   6 +
>  libavdevice/Makefile  |   1 +
>  libavdevice/alldevices.c  |   1 +
>  libavdevice/android_capture.c | 782 
> ++
>  libavdevice/android_capture.h |  77 +
>  5 files changed, 867 insertions(+)
>  create mode 100644 libavdevice/android_capture.c
>  create mode 100644 libavdevice/android_capture.h

A Changelog entry, documentation in doc/indevs.texi, and a libavdevice
version bump need to be added.

>  # indevs / outdevs
> +android_capture_indev_deps="android mediandk camera2ndk pthreads"
> +android_capture_indev_extralibs="-landroid -lmediandk -lcamera2ndk"
>  alsa_indev_deps="alsa"
>  alsa_outdev_deps="alsa"

Alphabetical order.

> +av_log(avctx, AV_LOG_ERROR, "Error %d on camera with id %s.\n", error,
> +ACameraDevice_getId(device));

As Nicolas suggested, can you stringify the error codes?

> +av_log(avctx, AV_LOG_ERROR,
> +"Failed to get camera id list, camera_status_t: %d.\n", ret);

camera_status_t seems like an internal naming. (Also media_status_t and
the likes.) Not sure whether other words would be better. Without
stringification, it's only useful to the developer anyway.

> +av_log(avctx, AV_LOG_ERROR,
> +"real-time buffer of [%s input] too full or near too full 
> (%d%% of size: %d [rtbufsize parameter])! frame dropped!\n",
> +stream_name, buffer_fullness, avctx->max_picture_buffer);

I (personally) mislike exclamation marks in messages.

> +{ "sample_rate", "set audio sample rate", OFFSET(sample_rate), 
> AV_OPT_TYPE_INT, {.i64 = 0}, 0, INT_MAX, DEC },
> +{ "sample_size", "set audio sample size", OFFSET(sample_size), 
> AV_OPT_TYPE_INT, {.i64 = 0}, 0, 16, DEC },
> +{ "channels", "set number of audio channels, such as 1 or 2", 
> OFFSET(channels), AV_OPT_TYPE_INT, {.i64 = 0}, 0, INT_MAX, DEC },
> +{ "audio_buffer_size", "set audio device buffer latency size in 
> milliseconds (default is the device's default)", OFFSET(audio_buffer_size), 
> AV_OPT_TYPE_INT, {.i64 = 0}, 0, INT_MAX, DEC },

While these aren't being used, don't expose them. (Will disappear
anyway if you split the functionality.)

> +.long_name  = NULL_IF_CONFIG_SMALL("Android camera/microphone input 
> source via Android NDK APIs (Audio yet to be implemented)"),

Perhaps a bit verbose, but if you split it up into video and audio as
suggested by Nicolas, you can shorten it. (I'm not sure "via Android
NDK APIs" is the correct to present.)

Moritz
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH] Add android_capture indev

2017-11-02 Thread Nicolas George
Le duodi 12 brumaire, an CCXXVI, Felix Matouschek a écrit :
> I've written an indev for Android devices to allow capturing their builtin
> cameras.
> What needs to be done to merge this?

Thanks for the patch. It looks very interesting. Before considering
merging, there are a few technical point to address. See inline comments
below.

> From b21fc8729ef2e1d9867dd7652f2c6173378e4910 Mon Sep 17 00:00:00 2001
> From: Felix Matouschek 
> Date: Tue, 24 Oct 2017 13:11:23 +0200
> Subject: [PATCH] Add android_capture indev
> To: ffmpeg-devel@ffmpeg.org
> 
> This commit adds an indev for Android devices on API level 24+ which
> uses the Android NDK Camera2 API to capture video from builtin cameras
> 
> Signed-off-by: Felix Matouschek 
> ---
>  configure |   6 +
>  libavdevice/Makefile  |   1 +
>  libavdevice/alldevices.c  |   1 +

>  libavdevice/android_capture.c | 782 
> ++

When reading the subject of the mail, I first thought it would be about
screen capture. Furthermore, there is code for audio, but it is not
connected to anything, and it does not seem that the android API
connects audio and video together.

For all these reasons, I suggest you name this device maybe
android_camera, and keep android_mic for audio capture.

>  libavdevice/android_capture.h |  77 +

This header is only used once, it does not need to be separate.

>  5 files changed, 867 insertions(+)
>  create mode 100644 libavdevice/android_capture.c
>  create mode 100644 libavdevice/android_capture.h
> 
> diff --git a/configure b/configure
> index 7a53bc76c7..e2165f2ff9 100755
> --- a/configure
> +++ b/configure
> @@ -3068,6 +3068,8 @@ xmv_demuxer_select="riffdec"
>  xwma_demuxer_select="riffdec"
>  
>  # indevs / outdevs
> +android_capture_indev_deps="android mediandk camera2ndk pthreads"
> +android_capture_indev_extralibs="-landroid -lmediandk -lcamera2ndk"
>  alsa_indev_deps="alsa"
>  alsa_outdev_deps="alsa"
>  avfoundation_indev_deps="avfoundation corevideo coremedia pthreads"
> @@ -5836,6 +5838,10 @@ check_lib shell32  "windows.h shellapi.h" 
> CommandLineToArgvW   -lshell32
>  check_lib wincrypt "windows.h wincrypt.h" CryptGenRandom   -ladvapi32
>  check_lib psapi"windows.h psapi.h"GetProcessMemoryInfo -lpsapi
>  
> +check_lib android android/native_window.h ANativeWindow_acquire -landroid
> +check_lib mediandk "stdint.h media/NdkImage.h" AImage_delete -lmediandk
> +check_lib camera2ndk "stdbool.h stdint.h camera/NdkCameraManager.h" 
> ACameraManager_create -lcamera2ndk
> +
>  enabled appkit   && check_apple_framework AppKit
>  enabled audiotoolbox && check_apple_framework AudioToolbox
>  enabled avfoundation && check_apple_framework AVFoundation
> diff --git a/libavdevice/Makefile b/libavdevice/Makefile
> index 8228d62147..aa01dd7e24 100644
> --- a/libavdevice/Makefile
> +++ b/libavdevice/Makefile
> @@ -14,6 +14,7 @@ OBJS-$(CONFIG_SHARED)+= reverse.o
>  # input/output devices
>  OBJS-$(CONFIG_ALSA_INDEV)+= alsa_dec.o alsa.o timefilter.o
>  OBJS-$(CONFIG_ALSA_OUTDEV)   += alsa_enc.o alsa.o
> +OBJS-$(CONFIG_ANDROID_CAPTURE_INDEV) += android_capture.o
>  OBJS-$(CONFIG_AVFOUNDATION_INDEV)+= avfoundation.o
>  OBJS-$(CONFIG_BKTR_INDEV)+= bktr.o
>  OBJS-$(CONFIG_CACA_OUTDEV)   += caca.o
> diff --git a/libavdevice/alldevices.c b/libavdevice/alldevices.c
> index b767b6a718..6cd57aa88a 100644
> --- a/libavdevice/alldevices.c
> +++ b/libavdevice/alldevices.c
> @@ -42,6 +42,7 @@ static void register_all(void)
>  {
>  /* devices */
>  REGISTER_INOUTDEV(ALSA, alsa);
> +REGISTER_INDEV   (ANDROID_CAPTURE,  android_capture);
>  REGISTER_INDEV   (AVFOUNDATION, avfoundation);
>  REGISTER_INDEV   (BKTR, bktr);
>  REGISTER_OUTDEV  (CACA, caca);
> diff --git a/libavdevice/android_capture.c b/libavdevice/android_capture.c
> new file mode 100644
> index 00..be0dee8f81
> --- /dev/null
> +++ b/libavdevice/android_capture.c
> @@ -0,0 +1,782 @@
> +/*
> + * Android camera/microphone input source via Android NDK APIs (Audio yet to 
> be implemented)
> + *
> + * Copyright (C) 2017 Felix Matouschek
> + *
> + * This file is part of FFmpeg.
> + *
> + * FFmpeg is free software; you can redistribute it and/or
> + * modify it under the terms of the GNU Lesser General Public
> + * License as published by the Free Software Foundation; either
> + * version 2.1 of the License, or (at your option) any later version.
> + *
> + * FFmpeg is distributed in the hope that it will be useful,
> + * but WITHOUT ANY WARRANTY; without even the implied warranty of
> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
> + * Lesser General Public License for more details.
> + *
> + * You should have received a copy of the GNU Lesser General Public
> + * License along with FFmpeg; if