Skip to content

Commit

Permalink
Create a real surface to receive the camera preview image.
Browse files Browse the repository at this point in the history
  • Loading branch information
tianli committed Aug 16, 2020
1 parent 9644a07 commit 91ddf5e
Show file tree
Hide file tree
Showing 318 changed files with 74,853 additions and 81 deletions.
2 changes: 1 addition & 1 deletion build.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#!/bin/sh

clang++ -o ndk-camera src/main.cc -lcamera2ndk -landroid -lmediandk -llog -lnativewindow -lc
clang++ -o ndk-camera src/main.cc -I libs/ -lcamera2ndk -landroid -lmediandk -llog -lnativewindow -lc -lgui -lui -lutils
54 changes: 54 additions & 0 deletions libs/android-base/chrono_utils.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/*
* Copyright (C) 2017 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#ifndef ANDROID_BASE_CHRONO_UTILS_H
#define ANDROID_BASE_CHRONO_UTILS_H

#include <chrono>
#include <sstream>

using namespace std::chrono_literals;

namespace android {
namespace base {

// A std::chrono clock based on CLOCK_BOOTTIME.
class boot_clock {
public:
typedef std::chrono::nanoseconds duration;
typedef std::chrono::time_point<boot_clock, duration> time_point;

static time_point now();
};

class Timer {
public:
Timer() : start_(boot_clock::now()) {}

std::chrono::milliseconds duration() const {
return std::chrono::duration_cast<std::chrono::milliseconds>(boot_clock::now() - start_);
}

private:
boot_clock::time_point start_;
};

std::ostream& operator<<(std::ostream& os, const Timer& t);

} // namespace base
} // namespace android

#endif // ANDROID_BASE_CHRONO_UTILS_H
90 changes: 90 additions & 0 deletions libs/android-base/endian.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
/*
* Copyright (C) 2017 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#ifndef ANDROID_BASE_ENDIAN_H
#define ANDROID_BASE_ENDIAN_H

/* A cross-platform equivalent of bionic's <sys/endian.h>. */

#if defined(__BIONIC__)

#include <sys/endian.h>

#elif defined(__GLIBC__)

/* glibc's <endian.h> is like bionic's <sys/endian.h>. */
#include <endian.h>

/* glibc keeps htons and htonl in <netinet/in.h>. */
#include <netinet/in.h>

/* glibc doesn't have the 64-bit variants. */
#define htonq(x) htobe64(x)
#define ntohq(x) be64toh(x)

/* glibc has different names to BSD for these. */
#define betoh16(x) be16toh(x)
#define betoh32(x) be32toh(x)
#define betoh64(x) be64toh(x)

#else

/* Mac OS and Windows have nothing. */

#define __LITTLE_ENDIAN 1234
#define LITTLE_ENDIAN __LITTLE_ENDIAN

#define __BIG_ENDIAN 4321
#define BIG_ENDIAN __BIG_ENDIAN

#define __BYTE_ORDER __LITTLE_ENDIAN
#define BYTE_ORDER __BYTE_ORDER

#define htons(x) __builtin_bswap16(x)
#define htonl(x) __builtin_bswap32(x)
#define htonq(x) __builtin_bswap64(x)

#define ntohs(x) __builtin_bswap16(x)
#define ntohl(x) __builtin_bswap32(x)
#define ntohq(x) __builtin_bswap64(x)

#define htobe16(x) __builtin_bswap16(x)
#define htobe32(x) __builtin_bswap32(x)
#define htobe64(x) __builtin_bswap64(x)

#define betoh16(x) __builtin_bswap16(x)
#define betoh32(x) __builtin_bswap32(x)
#define betoh64(x) __builtin_bswap64(x)

#define htole16(x) (x)
#define htole32(x) (x)
#define htole64(x) (x)

#define letoh16(x) (x)
#define letoh32(x) (x)
#define letoh64(x) (x)

#define be16toh(x) __builtin_bswap16(x)
#define be32toh(x) __builtin_bswap32(x)
#define be64toh(x) __builtin_bswap64(x)

#define le16toh(x) (x)
#define le32toh(x) (x)
#define le64toh(x) (x)

#endif

#endif // ANDROID_BASE_ENDIAN_H
46 changes: 46 additions & 0 deletions libs/android-base/errors.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
* Copyright (C) 2016 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

// Portable error handling functions. This is only necessary for host-side
// code that needs to be cross-platform; code that is only run on Unix should
// just use errno and strerror() for simplicity.
//
// There is some complexity since Windows has (at least) three different error
// numbers, not all of which share the same type:
// * errno: for C runtime errors.
// * GetLastError(): Windows non-socket errors.
// * WSAGetLastError(): Windows socket errors.
// errno can be passed to strerror() on all platforms, but the other two require
// special handling to get the error string. Refer to Microsoft documentation
// to determine which error code to check for each function.

#ifndef ANDROID_BASE_ERRORS_H
#define ANDROID_BASE_ERRORS_H

#include <string>

namespace android {
namespace base {

// Returns a string describing the given system error code. |error_code| must
// be errno on Unix or GetLastError()/WSAGetLastError() on Windows. Passing
// errno on Windows has undefined behavior.
std::string SystemErrorCodeToString(int error_code);

} // namespace base
} // namespace android

#endif // ANDROID_BASE_ERRORS_H
65 changes: 65 additions & 0 deletions libs/android-base/file.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
/*
* Copyright (C) 2015 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#ifndef ANDROID_BASE_FILE_H
#define ANDROID_BASE_FILE_H

#include <sys/stat.h>
#include <string>

#if !defined(_WIN32) && !defined(O_BINARY)
#define O_BINARY 0
#endif

namespace android {
namespace base {

bool ReadFdToString(int fd, std::string* content);
bool ReadFileToString(const std::string& path, std::string* content,
bool follow_symlinks = false);

bool WriteStringToFile(const std::string& content, const std::string& path,
bool follow_symlinks = false);
bool WriteStringToFd(const std::string& content, int fd);

#if !defined(_WIN32)
bool WriteStringToFile(const std::string& content, const std::string& path,
mode_t mode, uid_t owner, gid_t group,
bool follow_symlinks = false);
#endif

bool ReadFully(int fd, void* data, size_t byte_count);
bool WriteFully(int fd, const void* data, size_t byte_count);

bool RemoveFileIfExists(const std::string& path, std::string* err = nullptr);

#if !defined(_WIN32)
bool Realpath(const std::string& path, std::string* result);
bool Readlink(const std::string& path, std::string* result);
#endif

std::string GetExecutablePath();
std::string GetExecutableDirectory();

// Like the regular basename and dirname, but thread-safe on all
// platforms and capable of correctly handling exotic Windows paths.
std::string Basename(const std::string& path);
std::string Dirname(const std::string& path);

} // namespace base
} // namespace android

#endif // ANDROID_BASE_FILE_H
Loading

0 comments on commit 91ddf5e

Please sign in to comment.