Media kit: Suppress -Werror=class-memaccess

* Add media_format::Clear(), media_format::Unflatten().
* Replace memset() with media_format::Clear()
* Replace memcpy() with media_format::Unflatten()

Fix #14156

Change-Id: I38ebc2de4915b954a15b6f4f6b40d016506910e5
This commit is contained in:
Murai Takashi 2018-05-19 08:37:20 +09:00 committed by waddlesplash
parent 8547d09e97
commit 12ed45b60f
8 changed files with 39 additions and 16 deletions

View File

@ -604,6 +604,9 @@ public:
const void* MetaData() const;
int32 MetaDataSize() const;
void Unflatten(const char *flatBuffer);
void Clear();
media_format();
media_format(const media_format& other);
~media_format();

View File

@ -558,8 +558,8 @@ AddOnManager::_RegisterEncoder(EncoderPlugin* plugin, const entry_ref& ref)
while (true) {
memset(&info.codecInfo, 0, sizeof(media_codec_info));
memset(&info.intputFormat, 0, sizeof(media_format));
memset(&info.outputFormat, 0, sizeof(media_format));
info.intputFormat.Clear();
info.outputFormat.Clear();
if (plugin->RegisterNextEncoder(&cookie,
&info.codecInfo, &info.formatFamily, &info.intputFormat,
&info.outputFormat) != B_OK) {

View File

@ -442,11 +442,13 @@ dormant_flavor_info::Unflatten(type_code c, const void *buffer, ssize_t size)
if (!in_formats)
return B_NO_MEMORY;
// TODO: we should not!!! make flat copies of media_format
memcpy(const_cast<media_format *>(in_formats), buf,
count * sizeof(media_format));
for (int32 i = 0; i < count; i++) {
const_cast<media_format*>
(&in_formats[i])->Unflatten(buf);
buf += sizeof(media_format); // TODO: not save
}
in_format_count = count;
}
buf += count * sizeof(media_format); // TODO: not save
}
count = *(int32*)buf; buf += sizeof(int32);
@ -458,11 +460,13 @@ dormant_flavor_info::Unflatten(type_code c, const void *buffer, ssize_t size)
if (!out_formats)
return B_NO_MEMORY;
// TODO: we should not!!! make flat copies of media_format
memcpy(const_cast<media_format *>(out_formats), buf,
count * sizeof(media_format));
for (int32 i = 0; i < count; i++) {
const_cast<media_format*>
(&out_formats[i])->Unflatten(buf);
buf += sizeof(media_format); // TODO: not save
}
out_format_count = count;
}
buf += count * sizeof(media_format); // TODO: not save
}
node_info = *(dormant_node_info*)buf; buf += sizeof(dormant_node_info);

View File

@ -832,17 +832,34 @@ media_format::MetaDataSize() const
}
media_format::media_format()
void
media_format::Unflatten(const char *flatBuffer)
{
// TODO: we should not!!! make flat copies of media_format
memcpy(this, flatBuffer, sizeof(*this));
meta_data = NULL;
meta_data_area = B_BAD_VALUE;
}
void
media_format::Clear()
{
memset(this, 0x00, sizeof(*this));
meta_data = NULL;
meta_data_area = B_BAD_VALUE;
}
media_format::media_format()
{
this->Clear();
}
media_format::media_format(const media_format& other)
{
memset(this, 0x00, sizeof(*this));
meta_data_area = B_BAD_VALUE;
this->Clear();
*this = other;
}

View File

@ -96,8 +96,7 @@ MediaExtractor::_Init(BDataIO* source, int32 flags)
fStreamInfo[i].chunkCache
= new ChunkCache(fExtractorWaitSem, kMaxCacheBytes);
fStreamInfo[i].lastChunk = NULL;
memset(&fStreamInfo[i].encodedFormat, 0,
sizeof(fStreamInfo[i].encodedFormat));
fStreamInfo[i].encodedFormat.Clear();
if (fStreamInfo[i].chunkCache->InitCheck() != B_OK) {
fInitStatus = B_NO_MEMORY;

View File

@ -489,7 +489,7 @@ BMediaFormats::GetFormatFor(const media_format_description& description,
meta_format::CompareDescriptions);
TRACE("meta format == %p\n", metaFormat);
if (metaFormat == NULL) {
memset(_format, 0, sizeof(*_format)); // clear to widlcard
_format->Clear(); // clear to widlcard
return B_MEDIA_BAD_FORMAT;
}

View File

@ -3236,7 +3236,7 @@ BMediaRoster::GetFormatFor(const media_input& input, media_format* _format,
status_t rv;
request.dest = input.destination;
memset(&request.format, 0, sizeof(request.format)); // wildcard
request.format.Clear(); // wildcard
rv = QueryPort(input.destination.port, CONSUMER_ACCEPT_FORMAT, &request,
sizeof(request), &reply, sizeof(reply));

View File

@ -135,7 +135,7 @@ void
BTrackReader::SetToTrack(BMediaTrack *track)
{
media_format fmt;
memset(&fmt, 0, sizeof(fmt)); //wildcard
fmt.Clear(); //wildcard
memcpy(&fmt.u.raw_audio, &fFormat, sizeof(fFormat));
fmt.type = B_MEDIA_RAW_AUDIO;
//try to find a output format