MediaProfiles: expose CamcorderProfile objects for clients

Previously fields were retrieved via a central get(id1, id2, name) getter
that did not scale well to multiple encoder profiles for a single
object.

Expose the sub-objects directly with proper getters.

Bug: 171673898
Test: atest CamcorderProfileTest
Change-Id: Ia8e2451f3d4fe2c013da69aa6b26e60d66598a32
diff --git a/media/libmedia/MediaProfiles.cpp b/media/libmedia/MediaProfiles.cpp
index e6fe408..9c24cba 100644
--- a/media/libmedia/MediaProfiles.cpp
+++ b/media/libmedia/MediaProfiles.cpp
@@ -1121,6 +1121,36 @@
     return index;
 }
 
+const MediaProfiles::CamcorderProfile *MediaProfiles::getCamcorderProfile(
+            int cameraId, camcorder_quality quality) const {
+    int index = getCamcorderProfileIndex(cameraId, quality);
+    if (index == -1) {
+        ALOGE("The given camcorder profile camera %d quality %d is not found",
+            cameraId, quality);
+        return nullptr;
+    }
+
+    return mCamcorderProfiles[index];
+}
+
+std::vector<const MediaProfiles::AudioCodec *>
+MediaProfiles::CamcorderProfile::getAudioCodecs() const {
+    std::vector<const MediaProfiles::AudioCodec *> res;
+    for (const MediaProfiles::AudioCodec &ac : mAudioCodecs) {
+        res.push_back(&ac);
+    }
+    return res;
+}
+
+std::vector<const MediaProfiles::VideoCodec *>
+MediaProfiles::CamcorderProfile::getVideoCodecs() const {
+    std::vector<const MediaProfiles::VideoCodec *> res;
+    for (const MediaProfiles::VideoCodec &vc : mVideoCodecs) {
+        res.push_back(&vc);
+    }
+    return res;
+}
+
 int MediaProfiles::getCamcorderProfileParamByName(const char *name,
                                                   int cameraId,
                                                   camcorder_quality quality) const
diff --git a/media/libmedia/include/media/MediaProfiles.h b/media/libmedia/include/media/MediaProfiles.h
index 133448a..d06fda2 100644
--- a/media/libmedia/include/media/MediaProfiles.h
+++ b/media/libmedia/include/media/MediaProfiles.h
@@ -100,6 +100,176 @@
     static MediaProfiles* getInstance();
 
     /**
+     * Configuration for a video encoder.
+     */
+    struct VideoCodec {
+    public:
+        /**
+         * Constructs a video encoder configuration.
+         *
+         * @param codec codec type
+         * @param bitrate bitrate in bps
+         * @param frameWidth frame width in pixels
+         * @param frameHeight frame height in pixels
+         * @param frameRate frame rate in fps
+         */
+        VideoCodec(video_encoder codec, int bitrate, int frameWidth, int frameHeight, int frameRate)
+            : mCodec(codec),
+              mBitRate(bitrate),
+              mFrameWidth(frameWidth),
+              mFrameHeight(frameHeight),
+              mFrameRate(frameRate) {
+        }
+
+        VideoCodec(const VideoCodec&) = default;
+
+        ~VideoCodec() {}
+
+        /** Returns the codec type. */
+        video_encoder getCodec() const {
+            return mCodec;
+        }
+
+        /** Returns the bitrate in bps. */
+        int getBitrate() const {
+            return mBitRate;
+        }
+
+        /** Returns the frame width in pixels. */
+        int getFrameWidth() const {
+            return mFrameWidth;
+        }
+
+        /** Returns the frame height in pixels. */
+        int getFrameHeight() const {
+            return mFrameHeight;
+        }
+
+        /** Returns the frame rate in fps. */
+        int getFrameRate() const {
+            return mFrameRate;
+        }
+
+    private:
+        video_encoder mCodec;
+        int mBitRate;
+        int mFrameWidth;
+        int mFrameHeight;
+        int mFrameRate;
+        friend class MediaProfiles;
+    };
+
+    /**
+     * Configuration for an audio encoder.
+     */
+    struct AudioCodec {
+    public:
+        /**
+         * Constructs an audio encoder configuration.
+         *
+         * @param codec codec type
+         * @param bitrate bitrate in bps
+         * @param sampleRate sample rate in Hz
+         * @param channels number of channels
+         */
+        AudioCodec(audio_encoder codec, int bitrate, int sampleRate, int channels)
+            : mCodec(codec),
+              mBitRate(bitrate),
+              mSampleRate(sampleRate),
+              mChannels(channels) {
+        }
+
+        AudioCodec(const AudioCodec&) = default;
+
+        ~AudioCodec() {}
+
+        /** Returns the codec type. */
+        audio_encoder getCodec() const {
+            return mCodec;
+        }
+
+        /** Returns the bitrate in bps. */
+        int getBitrate() const {
+            return mBitRate;
+        }
+
+        /** Returns the sample rate in Hz. */
+        int getSampleRate() const {
+            return mSampleRate;
+        }
+
+        /** Returns the number of channels. */
+        int getChannels() const {
+            return mChannels;
+        }
+
+    private:
+        audio_encoder mCodec;
+        int mBitRate;
+        int mSampleRate;
+        int mChannels;
+        friend class MediaProfiles;
+    };
+
+    /**
+     * Configuration for a camcorder profile/encoder profiles object.
+     */
+    struct CamcorderProfile {
+        /**
+         *  Returns on ordered list of the video codec configurations in
+         *  decreasing preference. The returned object is only valid
+         *  during the lifetime of this object.
+         */
+        std::vector<const VideoCodec *> getVideoCodecs() const;
+
+        /**
+         *  Returns on ordered list of the audio codec configurations in
+         *  decreasing preference. The returned object is only valid
+         *  during the lifetime of this object.
+         */
+        std::vector<const AudioCodec *> getAudioCodecs() const;
+
+        /** Returns the default duration in seconds. */
+        int getDuration() const {
+            return mDuration;
+        }
+
+        /** Returns the preferred file format. */
+        int getFileFormat() const {
+            return mFileFormat;
+        }
+
+        CamcorderProfile(const CamcorderProfile& copy) = default;
+
+        ~CamcorderProfile() = default;
+
+    private:
+        /**
+         * Constructs an empty object with no audio/video profiles.
+         */
+        CamcorderProfile()
+            : mCameraId(0),
+              mFileFormat(OUTPUT_FORMAT_THREE_GPP),
+              mQuality(CAMCORDER_QUALITY_HIGH),
+              mDuration(0) {}
+
+        int mCameraId;
+        output_format mFileFormat;
+        camcorder_quality mQuality;
+        int mDuration;
+        std::vector<VideoCodec> mVideoCodecs;
+        std::vector<AudioCodec> mAudioCodecs;
+        friend class MediaProfiles;
+    };
+
+    /**
+     * Returns the CamcorderProfile object for the given camera at
+     * the given quality level, or null if it does not exist.
+     */
+    const CamcorderProfile *getCamcorderProfile(
+            int cameraId, camcorder_quality quality) const;
+
+    /**
      * Returns the value for the given param name for the given camera at
      * the given quality level, or -1 if error.
      *
@@ -202,72 +372,6 @@
     MediaProfiles() {}                               // Dummy default constructor
     ~MediaProfiles();                                // Don't delete me
 
-    struct VideoCodec {
-        VideoCodec(video_encoder codec, int bitRate, int frameWidth, int frameHeight, int frameRate)
-            : mCodec(codec),
-              mBitRate(bitRate),
-              mFrameWidth(frameWidth),
-              mFrameHeight(frameHeight),
-              mFrameRate(frameRate) {}
-
-        VideoCodec(const VideoCodec& copy) {
-            mCodec = copy.mCodec;
-            mBitRate = copy.mBitRate;
-            mFrameWidth = copy.mFrameWidth;
-            mFrameHeight = copy.mFrameHeight;
-            mFrameRate = copy.mFrameRate;
-        }
-
-        ~VideoCodec() {}
-
-        video_encoder mCodec;
-        int mBitRate;
-        int mFrameWidth;
-        int mFrameHeight;
-        int mFrameRate;
-    };
-
-    struct AudioCodec {
-        AudioCodec(audio_encoder codec, int bitRate, int sampleRate, int channels)
-            : mCodec(codec),
-              mBitRate(bitRate),
-              mSampleRate(sampleRate),
-              mChannels(channels) {}
-
-        AudioCodec(const AudioCodec& copy) {
-            mCodec = copy.mCodec;
-            mBitRate = copy.mBitRate;
-            mSampleRate = copy.mSampleRate;
-            mChannels = copy.mChannels;
-        }
-
-        ~AudioCodec() {}
-
-        audio_encoder mCodec;
-        int mBitRate;
-        int mSampleRate;
-        int mChannels;
-    };
-
-    struct CamcorderProfile {
-        CamcorderProfile()
-            : mCameraId(0),
-              mFileFormat(OUTPUT_FORMAT_THREE_GPP),
-              mQuality(CAMCORDER_QUALITY_HIGH),
-              mDuration(0) {}
-
-        CamcorderProfile(const CamcorderProfile& copy) = default;
-
-        ~CamcorderProfile() = default;
-
-        int mCameraId;
-        output_format mFileFormat;
-        camcorder_quality mQuality;
-        int mDuration;
-        std::vector<VideoCodec> mVideoCodecs;
-        std::vector<AudioCodec> mAudioCodecs;
-    };
-
     struct VideoEncoderCap {
         // Ugly constructor
         VideoEncoderCap(video_encoder codec,