Browse Source

[texture] Add camera width and height

embedder_texture
Vitaliy Zarubin 1 year ago
parent
commit
4db615def4
  1. 11
      example/lib/packages/embedder_texture/page.dart
  2. 39
      packages/embedder_texture/aurora/camera.cpp
  3. 2
      packages/embedder_texture/aurora/camera_pixels_helper.cpp
  4. 6
      packages/embedder_texture/aurora/embedder_texture_plugin.cpp
  5. 7
      packages/embedder_texture/aurora/include/embedder_texture/camera.h
  6. 32
      packages/embedder_texture/lib/embedder_texture.dart
  7. 10
      packages/embedder_texture/lib/embedder_texture_method_channel.dart
  8. 2
      packages/embedder_texture/lib/embedder_texture_platform_interface.dart

11
example/lib/packages/embedder_texture/page.dart

@ -31,16 +31,19 @@ class _EmbedderTexturePageState extends AppState<EmbedderTexturePage> {
MediaQueryData media,
AppLocalizations l10n,
) {
final width = MediaQuery.of(context).size.width;
final height = MediaQuery.of(context).size.height;
return BlockLayout<EmbedderTextureModel>(
model: getIt<EmbedderTextureModel>(),
title: widget.package.key,
builder: (context, child, model) {
return const Padding(
padding: EdgeInsets.all(20),
return Padding(
padding: const EdgeInsets.all(20),
child: Center(
child: EmbedderTexture(
width: 320,
height: 240,
width: width,
height: height,
),
),
);

39
packages/embedder_texture/aurora/camera.cpp

@ -26,19 +26,24 @@ void Camera::InitializeCamera(int cameraID)
}
}
void Camera::StartCapture()
Aurora::StreamCamera::CameraCapability Camera::StartCapture()
{
if (m_camera) {
Aurora::StreamCamera::CameraInfo info;
if (m_camera->getInfo(info)) {
std::vector<Aurora::StreamCamera::CameraCapability> caps;
if (m_manager->queryCapabilities(info.id, caps)) {
m_camera->startCapture(caps.at(1));
for(Aurora::StreamCamera::CameraCapability cap : caps) {
if (m_widthTexture + m_heightTexture < cap.width + cap.height) {
m_camera->startCapture(cap);
return cap;
}
}
}
}
}
return Aurora::StreamCamera::CameraCapability{};
}
void Camera::StopCapture()
@ -50,15 +55,22 @@ void Camera::StopCapture()
}
}
int64_t Camera::Register(int cameraID)
std::map<Encodable, Encodable> Camera::Register(int cameraID, int width, int height)
{
m_widthTexture = width;
m_heightTexture = height;
m_textureId = m_plugin->RegisterTexture(
[this](size_t width, size_t height) { return this->m_buffer; });
InitializeCamera(cameraID);
StartCapture();
auto cab = StartCapture();
return m_textureId;
return std::map<Encodable, Encodable>{
{"textureId", m_textureId},
{"width", cab.width},
{"height", cab.height},
};
}
void Camera::Unregister()
@ -72,10 +84,18 @@ void Camera::onCameraFrame(std::shared_ptr<Aurora::StreamCamera::GraphicBuffer>
if (buffer->handleType == Aurora::StreamCamera::HandleType::EGL) {
// @todo Not tested. The device needs to be completed.
auto eglImage = CameraEGLHelper::EGLCreateImage(buffer);
this->m_buffer = new TextureVariant(FlutterEGLImage{eglImage});
this->m_buffer = new TextureVariant(FlutterEGLImage{
eglImage,
buffer->width,
buffer->height,
});
} else {
auto pixels = CameraPixelsHelper::YUVtoARGB(buffer->mapYCbCr());
this->m_buffer = new TextureVariant(FlutterPixelBuffer{pixels});
this->m_buffer = new TextureVariant(FlutterPixelBuffer{
pixels,
buffer->width,
buffer->height,
});
}
m_plugin->MarkTextureAvailable(m_textureId);
@ -83,7 +103,8 @@ void Camera::onCameraFrame(std::shared_ptr<Aurora::StreamCamera::GraphicBuffer>
void Camera::onCameraError(const std::string &errorDescription)
{
std::cout << "onCameraError" << std::endl;
this->Unregister();
std::cout << errorDescription << std::endl;
}
void Camera::onCameraParameterChanged(Aurora::StreamCamera::CameraParameter parameter,

2
packages/embedder_texture/aurora/camera_pixels_helper.cpp

@ -10,8 +10,8 @@ uint8_t *CameraPixelsHelper::YUVtoARGB(std::shared_ptr<const Aurora::StreamCamer
QImage *image = new QImage(size, QImage::Format_ARGB32);
planarYuv420ToArgb(frame->y,
frame->cb,
frame->cr,
frame->cb,
frame->yStride,
frame->cStride,
frame->cStride,

6
packages/embedder_texture/aurora/embedder_texture_plugin.cpp

@ -36,10 +36,12 @@ void EmbedderTexturePlugin::onMethodCall(const MethodCall &call)
void EmbedderTexturePlugin::onCreate(const MethodCall &call)
{
auto cameraId = 0;
auto width = call.GetArgument<Encodable::Int>("width");
auto height = call.GetArgument<Encodable::Int>("height");
auto textureId = m_camera->Register(cameraId);
auto result = m_camera->Register(cameraId, width, height);
call.SendSuccessResponse(textureId);
call.SendSuccessResponse(result);
}
void EmbedderTexturePlugin::onRemove(const MethodCall &call)

7
packages/embedder_texture/aurora/include/embedder_texture/camera.h

@ -21,12 +21,12 @@ public:
void onCameraParameterChanged(Aurora::StreamCamera::CameraParameter,
const std::string &value) override;
int64_t Register(int cameraID);
std::map<Encodable, Encodable> Register(int cameraID, int width, int height);
void Unregister();
private:
void InitializeCamera(int cameraID);
void StartCapture();
Aurora::StreamCamera::CameraCapability StartCapture();
void StopCapture();
private:
@ -38,6 +38,9 @@ private:
int m_cameraId = -1;
int64_t m_textureId;
int m_widthTexture;
int m_heightTexture;
TextureVariant *m_buffer;
};

32
packages/embedder_texture/lib/embedder_texture.dart

@ -19,15 +19,19 @@ class EmbedderTexture extends StatefulWidget {
class _EmbedderTextureState extends State<EmbedderTexture> {
int _textureID = 0;
int _camera_width = 0;
int _camera_height = 0;
@override
initState() {
super.initState();
EmbedderTexturePlatform.instance
.create(widget.width, widget.height)
.then((value) => setState(() {
.then((data) => setState(() {
if (mounted) {
_textureID = value!;
_textureID = data['textureId']!;
_camera_width = data['width']!;
_camera_height = data['height']!;
debugPrint(_textureID.toString());
}
}));
@ -42,11 +46,31 @@ class _EmbedderTextureState extends State<EmbedderTexture> {
@override
Widget build(BuildContext context) {
if (_textureID != 0) {
return SizedBox(
double w = 0;
double h = 0;
if (MediaQuery.of(context).orientation == Orientation.portrait) {
w = _camera_width * widget.height / (widget.width - 40);
h = widget.width - 40;
} else {
w = _camera_height.toDouble();
h = widget.height - 40 - 56;
}
return Container(
color: Colors.black,
width: widget.width,
height: widget.height,
child: Center(
child: Texture(textureId: _textureID)
child: RotationTransition(
turns: AlwaysStoppedAnimation(MediaQuery.of(context).orientation == Orientation.portrait ? 90 / 360 : 0),
child: SizedBox(
width: w,
height: h,
child: Texture(textureId: _textureID)
),
)
),
);
}

10
packages/embedder_texture/lib/embedder_texture_method_channel.dart

@ -10,12 +10,12 @@ class MethodChannelEmbedderTexture extends EmbedderTexturePlatform {
final methodChannel = const MethodChannel('embedder_texture');
@override
Future<int?> create(double width, double height) async {
final version = await methodChannel.invokeMethod<int>('create', {
'width': width,
'height': height,
Future<Map<dynamic, dynamic>> create(double width, double height) async {
final data = await methodChannel.invokeMethod<Map<dynamic, dynamic>?>('create', {
'width': width.round(),
'height': height.round(),
});
return version;
return data ?? {};
}
@override

2
packages/embedder_texture/lib/embedder_texture_platform_interface.dart

@ -23,7 +23,7 @@ abstract class EmbedderTexturePlatform extends PlatformInterface {
_instance = instance;
}
Future<int?> create(double width, double height) {
Future<Map<dynamic, dynamic>> create(double width, double height) {
throw UnimplementedError('create() has not been implemented.');
}

Loading…
Cancel
Save