при копировании элементов очереди в объект изображения из метода MediaCodec.getInputImage(index) я столкнулся с проблемой, когда байтовые буферы успешно обрабатываются. скопировано, но метка времени не установлена.
ошибок не возникает, поэтому я очень запутался.
Очередь содержит объекты следующего класса.
Код: Выделить всё
class YUV420 {
public:
int width;
int height;
**long long timestampUs;**
std::vector planes;
YUV420(int width, int height, long long timestampUs)
: width(width), height(height), timestampUs(timestampUs) {
// Pre-allocate planes for Y, U, and V
planes.emplace_back(width * height, 1, width); // Y plane
planes.emplace_back(width * height / 2, 2, width); // U plane
planes.emplace_back(width * height / 2, 2, width); // V plane
}
....
Код: Выделить всё
extern "C"
JNIEXPORT void JNICALL
Java_com_example_YuvUtils_copyToImage2(
JNIEnv *env,
jobject /* this */,
jobject image // The MediaCodec Image object from Kotlin)
) {
...
YUV420 &yuvFrame = yuvQueue.dequeue();
jclass imageClass = env->GetObjectClass(image);
// Get the setTimestamp method ID
jmethodID setTimestampMethodID = env->GetMethodID(imageClass, "setTimestamp", "(J)V");
if (setTimestampMethodID == nullptr) {
LOGE("setTimestamp method not found in Image class.");
env->DeleteLocalRef(imageClass);
return;
}
// Call the setTimestamp method
env->CallVoidMethod(image, setTimestampMethodID, static_cast(yuvFrame.timestampUs));
// Check for exceptions
if (env->ExceptionCheck()) {
env->ExceptionDescribe(); // Print the exception to the log
env->ExceptionClear(); // Clear the exception so the JNI call can proceed
LOGE("Exception occurred while setting timestamp.");
} else {
LOGI("Timestamp set to %lld", yuvFrame.timestampUs);
}
// Verify the value by getting the current timestamp from the Image object
jmethodID getTimestampMethodID = env->GetMethodID(imageClass, "getTimestamp", "()J");
if (getTimestampMethodID == nullptr) {
LOGE("getTimestamp method not found in Image class.");
} else {
jlong retrievedTimestamp = env->CallLongMethod(image, getTimestampMethodID);
if (retrievedTimestamp == static_cast(yuvFrame.timestampUs)) {
LOGI("Timestamp verification succeeded.");
} else {
LOGE("Timestamp verification failed. Expected: %lld, but got: %lld",
yuvFrame.timestampUs, retrievedTimestamp);
}
}
// planes will be copied below.... that part is working
}
Код: Выделить всё
Timestamp set to 608659736453232
Код: Выделить всё
Timestamp verification failed. Expected: 608659736453232, but got: 0
Спасибо!
Подробнее здесь: https://stackoverflow.com/questions/789 ... ive-c-code