Skip to content
This repository has been archived by the owner on Jan 5, 2025. It is now read-only.

Commit

Permalink
Add private Impl classes to other public types.
Browse files Browse the repository at this point in the history
This will allow us to add additional fields in the future without
breaking ABI if we need to.

Abi-Breaking: Changes size of some types.
Change-Id: Id6a49af13d5acaa1fe1dbf88877d5c29b8367d4f
  • Loading branch information
TheModMaker committed May 26, 2020
1 parent 6d9e2c3 commit d251649
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 3 deletions.
13 changes: 13 additions & 0 deletions shaka/include/shaka/media/frames.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#define SHAKA_EMBEDDED_MEDIA_FRAMES_H_

#include <iostream>
#include <memory>
#include <vector>

#include "../eme/configuration.h"
Expand Down Expand Up @@ -217,6 +218,10 @@ class SHAKA_EXPORT BaseFrame {
* @return The estimated size of the frame, in bytes.
*/
virtual size_t EstimateSize() const;

private:
class Impl;
std::unique_ptr<Impl> impl_;
};

/**
Expand Down Expand Up @@ -264,6 +269,10 @@ class SHAKA_EXPORT EncodedFrame : public BaseFrame {


size_t EstimateSize() const override;

private:
class Impl;
std::unique_ptr<Impl> impl_;
};

/**
Expand Down Expand Up @@ -317,6 +326,10 @@ class SHAKA_EXPORT DecodedFrame : public BaseFrame {


size_t EstimateSize() const override;

private:
class Impl;
std::unique_ptr<Impl> impl_;
};

} // namespace media
Expand Down
2 changes: 2 additions & 0 deletions shaka/include/shaka/media/media_track.h
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,8 @@ class SHAKA_EXPORT MediaTrack {
virtual void SetEnabled(bool enabled);

private:
class Impl;
std::unique_ptr<Impl> impl_;
bool enabled_;
};

Expand Down
18 changes: 15 additions & 3 deletions shaka/src/media/frames.cc
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,8 @@ size_t GetPlaneCount(variant<PixelFormat, SampleFormat> format,
}


class BaseFrame::Impl {};

BaseFrame::BaseFrame(std::shared_ptr<const StreamInfo> stream_info, double pts,
double dts, double duration, bool is_key_frame)
: stream_info(stream_info),
Expand All @@ -120,10 +122,12 @@ BaseFrame::BaseFrame(std::shared_ptr<const StreamInfo> stream_info, double pts,
BaseFrame::~BaseFrame() {}

size_t BaseFrame::EstimateSize() const {
return sizeof(*this);
return sizeof(*this) + sizeof(Impl);
}


class EncodedFrame::Impl {};

EncodedFrame::EncodedFrame(
std::shared_ptr<const StreamInfo> stream, double pts, double dts,
double duration, bool is_key_frame, const uint8_t* data, size_t data_size,
Expand Down Expand Up @@ -156,10 +160,15 @@ MediaStatus EncodedFrame::Decrypt(const eme::Implementation* implementation,
}

size_t EncodedFrame::EstimateSize() const {
return sizeof(*this) + data_size;
// BaseFrame::EstimateSize includes sizeof(BaseFrame) and so does
// sizeof(this), so we need to remove the extra.
return BaseFrame::EstimateSize() + sizeof(*this) - sizeof(BaseFrame) +
data_size + sizeof(Impl);
}


class DecodedFrame::Impl {};

DecodedFrame::DecodedFrame(std::shared_ptr<const StreamInfo> stream, double pts,
double dts, double duration,
variant<PixelFormat, SampleFormat> format,
Expand All @@ -174,7 +183,10 @@ DecodedFrame::DecodedFrame(std::shared_ptr<const StreamInfo> stream, double pts,
DecodedFrame::~DecodedFrame() {}

size_t DecodedFrame::EstimateSize() const {
size_t ret = sizeof(*this);
// BaseFrame::EstimateSize includes sizeof(BaseFrame) and so does
// sizeof(this), so we need to remove the extra.
size_t ret = BaseFrame::EstimateSize() + sizeof(*this) - sizeof(BaseFrame) +
sizeof(Impl);
for (size_t line : linesize) {
if (holds_alternative<PixelFormat>(format))
ret += line * stream_info->height;
Expand Down
2 changes: 2 additions & 0 deletions shaka/src/media/media_track_public.cc
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
namespace shaka {
namespace media {

class MediaTrack::Impl {};

MediaTrack::MediaTrack(MediaTrackKind kind, const std::string& label,
const std::string& language, const std::string& id)
: label(label), language(language), id(id), kind(kind), enabled_(false) {}
Expand Down

0 comments on commit d251649

Please sign in to comment.