Skip to content

Instantly share code, notes, and snippets.

@RLovelett
Last active December 15, 2015 16:12
Show Gist options
  • Save RLovelett/e5ee7f173877bb8475dc to your computer and use it in GitHub Desktop.
Save RLovelett/e5ee7f173877bb8475dc to your computer and use it in GitHub Desktop.
Allow `withUnsafePointer` to not mark `struct` function as `mutating`
extension AVCodec {
mutating func profileName(profile: Int32) -> String? {
let result = withUnsafePointer(&self) { (codecPointer) in
return av_get_profile_name(codecPointer, profile)
}
return String.fromCString(result)
}
}
// See: https://ffmpeg.org/doxygen/2.8/libavcodec_2avcodec_8h_source.html#l03472
typedef struct AVCodec {
// ...
} AVCodec;
// See: https://ffmpeg.org/doxygen/2.8/libavcodec_2utils_8c_source.html#l03260
const char *av_get_profile_name(const AVCodec *codec, int profile)
{
const AVProfile *p;
if (profile == FF_PROFILE_UNKNOWN || !codec->profiles)
return NULL;
for (p = codec->profiles; p->profile != FF_PROFILE_UNKNOWN; p++)
if (p->profile == profile)
return p->name;
return NULL;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment