SessionConfiguration.cpp 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. /*
  2. **
  3. ** Copyright 2018, The Android Open Source Project
  4. **
  5. ** Licensed under the Apache License, Version 2.0 (the "License");
  6. ** you may not use this file except in compliance with the License.
  7. ** You may obtain a copy of the License at
  8. **
  9. ** http://www.apache.org/licenses/LICENSE-2.0
  10. **
  11. ** Unless required by applicable law or agreed to in writing, software
  12. ** distributed under the License is distributed on an "AS IS" BASIS,
  13. ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. ** See the License for the specific language governing permissions and
  15. ** limitations under the License.
  16. */
  17. #define LOG_TAG "SessionConfiguration"
  18. //#define LOG_NDEBUG 0
  19. #include <utils/Log.h>
  20. #include <camera/camera2/SessionConfiguration.h>
  21. #include <camera/camera2/OutputConfiguration.h>
  22. #include <binder/Parcel.h>
  23. namespace android {
  24. status_t SessionConfiguration::readFromParcel(const android::Parcel* parcel) {
  25. status_t err = OK;
  26. int operatingMode = 0;
  27. if (parcel == nullptr) return BAD_VALUE;
  28. if ((err = parcel->readInt32(&operatingMode)) != OK) {
  29. ALOGE("%s: Failed to read operating mode from parcel", __FUNCTION__);
  30. return err;
  31. }
  32. int inputWidth = 0;
  33. if ((err = parcel->readInt32(&inputWidth)) != OK) {
  34. ALOGE("%s: Failed to read input width from parcel", __FUNCTION__);
  35. return err;
  36. }
  37. int inputHeight = 0;
  38. if ((err = parcel->readInt32(&inputHeight)) != OK) {
  39. ALOGE("%s: Failed to read input height from parcel", __FUNCTION__);
  40. return err;
  41. }
  42. int inputFormat = -1;
  43. if ((err = parcel->readInt32(&inputFormat)) != OK) {
  44. ALOGE("%s: Failed to read input format from parcel", __FUNCTION__);
  45. return err;
  46. }
  47. std::vector<OutputConfiguration> outputStreams;
  48. if ((err = parcel->readParcelableVector(&outputStreams)) != OK) {
  49. ALOGE("%s: Failed to read output configurations from parcel", __FUNCTION__);
  50. return err;
  51. }
  52. mOperatingMode = operatingMode;
  53. mInputWidth = inputWidth;
  54. mInputHeight = inputHeight;
  55. mInputFormat = inputFormat;
  56. for (auto& stream : outputStreams) {
  57. mOutputStreams.push_back(stream);
  58. }
  59. return err;
  60. }
  61. status_t SessionConfiguration::writeToParcel(android::Parcel* parcel) const {
  62. if (parcel == nullptr) return BAD_VALUE;
  63. status_t err = OK;
  64. err = parcel->writeInt32(mOperatingMode);
  65. if (err != OK) return err;
  66. err = parcel->writeInt32(mInputWidth);
  67. if (err != OK) return err;
  68. err = parcel->writeInt32(mInputHeight);
  69. if (err != OK) return err;
  70. err = parcel->writeInt32(mInputFormat);
  71. if (err != OK) return err;
  72. err = parcel->writeParcelableVector(mOutputStreams);
  73. if (err != OK) return err;
  74. return OK;
  75. }
  76. bool SessionConfiguration::outputsEqual(const SessionConfiguration& other) const {
  77. const std::vector<OutputConfiguration>& otherOutputStreams =
  78. other.getOutputConfigurations();
  79. if (mOutputStreams.size() != otherOutputStreams.size()) {
  80. return false;
  81. }
  82. for (size_t i = 0; i < mOutputStreams.size(); i++) {
  83. if (mOutputStreams[i] != otherOutputStreams[i]) {
  84. return false;
  85. }
  86. }
  87. return true;
  88. }
  89. bool SessionConfiguration::outputsLessThan(const SessionConfiguration& other) const {
  90. const std::vector<OutputConfiguration>& otherOutputStreams =
  91. other.getOutputConfigurations();
  92. if (mOutputStreams.size() != otherOutputStreams.size()) {
  93. return mOutputStreams.size() < otherOutputStreams.size();
  94. }
  95. for (size_t i = 0; i < mOutputStreams.size(); i++) {
  96. if (mOutputStreams[i] != otherOutputStreams[i]) {
  97. return mOutputStreams[i] < otherOutputStreams[i];
  98. }
  99. }
  100. return false;
  101. }
  102. }; // namespace android