Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

64bit MMAL support #586

Merged
merged 4 commits into from
Dec 11, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 8 additions & 10 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,9 @@ SET(PROJECT_VER_PATCH 0)
SET(PROJECT_VER "${PROJECT_VER_MAJOR}.${PROJECT_VER_MINOR}.${PROJECT_VER_PATCH}")
SET(PROJECT_APIVER "${PROJECT_VER}")

if(ARM64)
set(BUILD_MMAL FALSE)
set(BUILD_MMAL_APPS FALSE)
else()
set(BUILD_MMAL TRUE)
set(BUILD_MMAL_APPS TRUE)
endif()
set(BUILD_MMAL TRUE)
set(BUILD_MMAL_APPS TRUE)

set(vmcs_root ${PROJECT_SOURCE_DIR})
get_filename_component(VIDEOCORE_ROOT . ABSOLUTE)

Expand Down Expand Up @@ -78,9 +74,11 @@ if(BUILD_MMAL)
endif()

# VidTex supports Android and Linux
if(BUILD_MMAL_APPS)
add_subdirectory(host_applications/android/apps/vidtex)
endif(BUILD_MMAL_APPS)
if(NOT ARM64)
if(BUILD_MMAL_APPS)
add_subdirectory(host_applications/android/apps/vidtex)
endif(BUILD_MMAL_APPS)
endif()

if(NOT ARM64)
add_subdirectory(middleware/openmaxil)
Expand Down
4 changes: 2 additions & 2 deletions host_applications/linux/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ add_subdirectory(libs/bcm_host)
add_subdirectory(apps/gencmd)
add_subdirectory(apps/tvservice)
add_subdirectory(apps/vcmailbox)
add_subdirectory(apps/raspicam)
add_subdirectory(libs/sm)
if(NOT ARM64)
add_subdirectory(apps/raspicam)
add_subdirectory(libs/sm)
add_subdirectory(apps/smem)
endif()
add_subdirectory(libs/debug_sym)
Expand Down
29 changes: 17 additions & 12 deletions host_applications/linux/apps/raspicam/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,6 @@ execute_process(
)
add_definitions("-DGIT_TAINTED=${GIT_TAINTED}")

set (GL_SCENE_SOURCES
gl_scenes/models.c
gl_scenes/mirror.c
gl_scenes/yuv.c
gl_scenes/sobel.c
gl_scenes/square.c
gl_scenes/teapot.c
gl_scenes/vcsm_square.c)

set (COMMON_SOURCES
RaspiCamControl.c
RaspiCLI.c
Expand All @@ -47,14 +38,28 @@ set (COMMON_SOURCES
RaspiGPS.c
libgps_loader.c)

add_executable(raspistill ${COMMON_SOURCES} RaspiStill.c RaspiTex.c RaspiTexUtil.c tga.c ${GL_SCENE_SOURCES} )
if(NOT ARM64)
set (EGL_LIBS brcmGLESv2 brcmEGL)
set (EGL_SOURCES RaspiTex.c RaspiTexUtil.c tga.c)
set (GL_SCENE_SOURCES
gl_scenes/models.c
gl_scenes/mirror.c
gl_scenes/yuv.c
gl_scenes/sobel.c
gl_scenes/square.c
gl_scenes/teapot.c
gl_scenes/vcsm_square.c)
else()
set (EGL_SOURCES RaspiTexStub.c)
endif()

add_executable(raspistill ${COMMON_SOURCES} RaspiStill.c ${EGL_SOURCES} ${GL_SCENE_SOURCES} )
add_executable(raspiyuv ${COMMON_SOURCES} RaspiStillYUV.c)
add_executable(raspivid ${COMMON_SOURCES} RaspiVid.c)
add_executable(raspividyuv ${COMMON_SOURCES} RaspiVidYUV.c)

set (MMAL_LIBS mmal_core mmal_util mmal_vc_client)

target_link_libraries(raspistill ${MMAL_LIBS} vcos bcm_host brcmGLESv2 brcmEGL m dl)
target_link_libraries(raspistill ${MMAL_LIBS} vcos bcm_host ${EGL_LIBS} m dl)
target_link_libraries(raspiyuv ${MMAL_LIBS} vcos bcm_host)
target_link_libraries(raspivid ${MMAL_LIBS} vcos bcm_host)
target_link_libraries(raspividyuv ${MMAL_LIBS} vcos bcm_host)
Expand Down
240 changes: 240 additions & 0 deletions host_applications/linux/apps/raspicam/RaspiTexStub.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,240 @@
/*
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wasn't expecting a new source file based on the commit message (which has a typo, BTW). A bit more explanation would be nice.

Copyright (c) 2013, Broadcom Europe Ltd
Copyright (c) 2013, Tim Gover
All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
* Neither the name of the copyright holder nor the
names of its contributors may be used to endorse or promote products
derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

#include "RaspiTex.h"
#include "RaspiCLI.h"
#include "interface/vcos/vcos.h"
#include "interface/mmal/mmal_buffer.h"
#include "interface/mmal/util/mmal_util.h"
#include "interface/mmal/util/mmal_util_params.h"

/**
* \file RaspiTex.c
*
* A simple framework for extending a MMAL application to render buffers via
* OpenGL.
*
* MMAL buffers are often in YUV colour space and in either a planar or
* tile format which is not supported directly by V3D. Instead of copying
* the buffer from the GPU and doing a colour space / pixel format conversion
* the GL_OES_EGL_image_external is used. This allows an EGL image to be
* created from GPU buffer handle (MMAL opaque buffer handle). The EGL image
* may then be used to create a texture (glEGLImageTargetTexture2DOES) and
* drawn by either OpenGL ES 1.0 or 2.0 contexts.
*
* Notes:
* 1) GL_OES_EGL_image_external textures always return pixels in RGBA format.
* This is also the case when used from a fragment shader.
*
* 2) The driver implementation creates a new RGB_565 buffer and does the color
* space conversion from YUV. This happens in GPU memory using the vector
* processor.
*
* 3) Each EGL external image in use will consume GPU memory for the RGB 565
* buffer. In addition, the GL pipeline might require more than one EGL image
* to be retained in GPU memory until the drawing commands are flushed.
*
* Typically 128 MB of GPU memory is sufficient for 720p viewfinder and 720p
* GL surface. If both the viewfinder and the GL surface are 1080p then
* 256MB of GPU memory is recommended, otherwise, for non-trivial scenes
* the system can run out of GPU memory whilst the camera is running.
*
* 4) It is important to make sure that the MMAL opaque buffer is not returned
* to MMAL before the GL driver has completed the asynchronous call to
* glEGLImageTargetTexture2DOES. Deferring destruction of the EGL image and
* the buffer return to MMAL until after eglSwapBuffers is the recommended.
*
* See also: http://www.khronos.org/registry/gles/extensions/OES/OES_EGL_image_external.txt
*/

#define DEFAULT_WIDTH 640
#define DEFAULT_HEIGHT 480

enum
{
CommandGLScene,
CommandGLWin
};

static COMMAND_LIST cmdline_commands[] =
{
{ CommandGLScene, "-glscene", "gs", "GL scene square,teapot,mirror,yuv,sobel,vcsm_square", 1 },
{ CommandGLWin, "-glwin", "gw", "GL window settings <'x,y,w,h'>", 1 },
};

static int cmdline_commands_size = sizeof(cmdline_commands) / sizeof(cmdline_commands[0]);

/**
* Parse a possible command pair - command and parameter
* @param arg1 Command
* @param arg2 Parameter (could be NULL)
* @return How many parameters were used, 0,1,2
*/
int raspitex_parse_cmdline(RASPITEX_STATE *state,
const char *arg1, const char *arg2)
{
int command_id, used = 0, num_parameters;

if (!arg1)
return 0;

command_id = raspicli_get_command_id(cmdline_commands,
cmdline_commands_size, arg1, &num_parameters);

// If invalid command, or we are missing a parameter, drop out
if (command_id==-1 || (command_id != -1 && num_parameters > 0 && arg2 == NULL))
return 0;

switch (command_id)
{
case CommandGLWin: // Allows a GL window to be different to preview-res
{
int tmp;
tmp = sscanf(arg2, "%d,%d,%d,%d",
&state->x, &state->y, &state->width, &state->height);
if (tmp != 4)
{
// Default to safe size on parse error
state->x = state->y = 0;
state->width = DEFAULT_WIDTH;
state->height = DEFAULT_HEIGHT;
}
else
{
state->gl_win_defined = 1;
}

used = 2;
break;
}

case CommandGLScene: // Selects the GL scene
{
if (strcmp(arg2, "square") == 0)
state->scene_id = RASPITEX_SCENE_SQUARE;
else if (strcmp(arg2, "teapot") == 0)
state->scene_id = RASPITEX_SCENE_TEAPOT;
else if (strcmp(arg2, "mirror") == 0)
state->scene_id = RASPITEX_SCENE_MIRROR;
else if (strcmp(arg2, "yuv") == 0)
state->scene_id = RASPITEX_SCENE_YUV;
else if (strcmp(arg2, "sobel") == 0)
state->scene_id = RASPITEX_SCENE_SOBEL;
else if (strcmp(arg2, "vcsm_square") == 0)
state->scene_id = RASPITEX_SCENE_VCSM_SQUARE;
else
fprintf(stderr, "Unknown scene %s", arg2);

used = 2;
break;
}
}
return used;
}

/**
* Display help for command line options
*/
void raspitex_display_help()
{
fprintf(stdout, "\nGL parameter commands\n\n");
raspicli_display_help(cmdline_commands, cmdline_commands_size);
}


/* Registers a callback on the camera preview port to receive
* notifications of new frames.
* This must be called before rapitex_start and may not be called again
* without calling raspitex_destroy first.
*
* @param state Pointer to the GL preview state.
* @param port Pointer to the camera preview port
* @return Zero if successful.
*/
int raspitex_configure_preview_port(RASPITEX_STATE *state,
MMAL_PORT_T *preview_port)
{
return -1;
}

/* Initialises GL preview state and creates the dispmanx native window.
* @param state Pointer to the GL preview state.
* @return Zero if successful.
*/
int raspitex_init(RASPITEX_STATE *state)
{
return -1;
}

/* Destroys the pools of buffers used by the GL renderer.
* @param state Pointer to the GL preview state.
*/
void raspitex_destroy(RASPITEX_STATE *state)
{
}

/* Initialise the GL / window state to sensible defaults.
* Also initialise any rendering parameters e.g. the scene
*
* @param state Pointer to the GL preview state.
* @return Zero if successful.
*/
void raspitex_set_defaults(RASPITEX_STATE *state)
{
}

/* Stops the rendering loop and destroys MMAL resources
* @param state Pointer to the GL preview state.
*/
void raspitex_stop(RASPITEX_STATE *state)
{
}

/**
* Starts the worker / GL renderer thread.
* @pre raspitex_init was successful
* @pre raspitex_configure_preview_port was successful
* @param state Pointer to the GL preview state.
* @return Zero on success, otherwise, -1 is returned
* */
int raspitex_start(RASPITEX_STATE *state)
{
return -1;
}

/**
* Writes the next GL frame-buffer to a RAW .ppm formatted file
* using the specified file-handle.
* @param state Pointer to the GL preview state.
* @param outpt_file Output file handle for the ppm image.
* @return Zero on success.
*/
int raspitex_capture(RASPITEX_STATE *state, FILE *output_file)
{
return -1;
}
Loading