mirror of
https://github.com/Evolution-X/hardware_interfaces
synced 2026-02-01 15:58:43 +00:00
Merge "Fix NativeHandle creation in TV Input HAL 2.0 default implementation"
This commit is contained in:
@@ -95,8 +95,8 @@ void TvInput::init() {
|
||||
return ::ndk::ScopedAStatus::fromServiceSpecificError(STATUS_INVALID_STATE);
|
||||
}
|
||||
mStreamConfigs[in_deviceId][in_streamId]->handle = createNativeHandle(in_streamId);
|
||||
mStreamConfigs[in_deviceId][in_streamId]->isOpen = true;
|
||||
*_aidl_return = makeToAidl(mStreamConfigs[in_deviceId][in_streamId]->handle);
|
||||
mStreamConfigs[in_deviceId][in_streamId]->isOpen = true;
|
||||
return ::ndk::ScopedAStatus::ok();
|
||||
}
|
||||
|
||||
@@ -112,27 +112,21 @@ void TvInput::init() {
|
||||
ALOGW("Stream with device id %d, stream id %d is already closed", in_deviceId, in_streamId);
|
||||
return ::ndk::ScopedAStatus::fromServiceSpecificError(STATUS_INVALID_STATE);
|
||||
}
|
||||
releaseNativeHandle(mStreamConfigs[in_deviceId][in_streamId]->handle);
|
||||
native_handle_delete(mStreamConfigs[in_deviceId][in_streamId]->handle);
|
||||
mStreamConfigs[in_deviceId][in_streamId]->handle = nullptr;
|
||||
mStreamConfigs[in_deviceId][in_streamId]->isOpen = false;
|
||||
return ::ndk::ScopedAStatus::ok();
|
||||
}
|
||||
|
||||
native_handle_t* TvInput::createNativeHandle(int fd) {
|
||||
native_handle_t* nativeHandle = native_handle_create(1, 0);
|
||||
if (nativeHandle == nullptr) {
|
||||
native_handle_t* handle = native_handle_create(1, 1);
|
||||
if (handle == nullptr) {
|
||||
ALOGE("[TVInput] Failed to create native_handle %d", errno);
|
||||
return nullptr;
|
||||
}
|
||||
if (nativeHandle->numFds > 0) {
|
||||
nativeHandle->data[0] = dup(fd);
|
||||
}
|
||||
return nativeHandle;
|
||||
}
|
||||
|
||||
void TvInput::releaseNativeHandle(native_handle_t* handle) {
|
||||
native_handle_close(handle);
|
||||
native_handle_delete(handle);
|
||||
handle->data[0] = dup(0);
|
||||
handle->data[1] = fd;
|
||||
return handle;
|
||||
}
|
||||
|
||||
} // namespace input
|
||||
|
||||
@@ -48,7 +48,6 @@ class TvInput : public BnTvInput {
|
||||
|
||||
private:
|
||||
native_handle_t* createNativeHandle(int fd);
|
||||
void releaseNativeHandle(native_handle_t* handle);
|
||||
|
||||
shared_ptr<ITvInputCallback> mCallback;
|
||||
map<int32_t, shared_ptr<TvInputDeviceInfoWrapper>> mDeviceInfos;
|
||||
|
||||
@@ -158,10 +158,11 @@ TEST_P(TvInputAidlTest, OpenAndCloseStreamTest) {
|
||||
int32_t device_id = stream_config_.keyAt(j);
|
||||
vector<TvStreamConfig> config = stream_config_.valueAt(j);
|
||||
for (size_t i = 0; i < config.size(); i++) {
|
||||
NativeHandle handle;
|
||||
int32_t stream_id = config[i].streamId;
|
||||
ALOGD("OpenAndCloseStreamTest: open stream, device_id=%d, stream_id=%d", device_id,
|
||||
stream_id);
|
||||
ASSERT_TRUE(tv_input_->openStream(device_id, stream_id, &handle_).isOk());
|
||||
ASSERT_TRUE(tv_input_->openStream(device_id, stream_id, &handle).isOk());
|
||||
ALOGD("OpenAndCloseStreamTest: close stream, device_id=%d, stream_id=%d", device_id,
|
||||
stream_id);
|
||||
ASSERT_TRUE(tv_input_->closeStream(device_id, stream_id).isOk());
|
||||
@@ -190,9 +191,10 @@ TEST_P(TvInputAidlTest, InvalidDeviceIdTest) {
|
||||
ITvInput::STATUS_INVALID_ARGUMENTS);
|
||||
|
||||
int32_t stream_id = 0;
|
||||
NativeHandle handle;
|
||||
|
||||
ALOGD("InvalidDeviceIdTest: open stream, device_id=%d, stream_id=%d", id, stream_id);
|
||||
ASSERT_TRUE(tv_input_->openStream(id, stream_id, &handle_).getServiceSpecificError() ==
|
||||
ASSERT_TRUE(tv_input_->openStream(id, stream_id, &handle).getServiceSpecificError() ==
|
||||
ITvInput::STATUS_INVALID_ARGUMENTS);
|
||||
|
||||
ALOGD("InvalidDeviceIdTest: close stream, device_id=%d, stream_id=%d", id, stream_id);
|
||||
@@ -226,8 +228,10 @@ TEST_P(TvInputAidlTest, InvalidStreamIdTest) {
|
||||
id = getNumNotIn(stream_ids);
|
||||
}
|
||||
|
||||
NativeHandle handle;
|
||||
|
||||
ALOGD("InvalidStreamIdTest: open stream, device_id=%d, stream_id=%d", device_id, id);
|
||||
ASSERT_TRUE(tv_input_->openStream(device_id, id, &handle_).getServiceSpecificError() ==
|
||||
ASSERT_TRUE(tv_input_->openStream(device_id, id, &handle).getServiceSpecificError() ==
|
||||
ITvInput::STATUS_INVALID_ARGUMENTS);
|
||||
|
||||
ALOGD("InvalidStreamIdTest: close stream, device_id=%d, stream_id=%d", device_id, id);
|
||||
@@ -252,11 +256,13 @@ TEST_P(TvInputAidlTest, OpenAnOpenedStreamsTest) {
|
||||
int32_t device_id = stream_config_.keyAt(indices[0]);
|
||||
int32_t stream_id = stream_config_.valueAt(indices[0])[0].streamId;
|
||||
|
||||
ALOGD("OpenAnOpenedStreamsTest: open stream, device_id=%d, stream_id=%d", device_id, stream_id);
|
||||
ASSERT_TRUE(tv_input_->openStream(device_id, stream_id, &handle_).isOk());
|
||||
NativeHandle handle;
|
||||
|
||||
ALOGD("OpenAnOpenedStreamsTest: open stream, device_id=%d, stream_id=%d", device_id, stream_id);
|
||||
ASSERT_TRUE(tv_input_->openStream(device_id, stream_id, &handle_).getServiceSpecificError() ==
|
||||
ASSERT_TRUE(tv_input_->openStream(device_id, stream_id, &handle).isOk());
|
||||
|
||||
ALOGD("OpenAnOpenedStreamsTest: open stream, device_id=%d, stream_id=%d", device_id, stream_id);
|
||||
ASSERT_TRUE(tv_input_->openStream(device_id, stream_id, &handle).getServiceSpecificError() ==
|
||||
ITvInput::STATUS_INVALID_STATE);
|
||||
|
||||
// close stream as subsequent tests assume no open streams
|
||||
|
||||
@@ -84,7 +84,6 @@ class TvInputAidlTest : public testing::TestWithParam<string> {
|
||||
android::KeyedVector<int32_t, TvInputDeviceInfo> device_info_;
|
||||
android::KeyedVector<int32_t, vector<TvStreamConfig>> stream_config_;
|
||||
mutex mutex_;
|
||||
NativeHandle handle_;
|
||||
};
|
||||
|
||||
} // namespace VtsHalTvInputTargetTest
|
||||
|
||||
Reference in New Issue
Block a user