Files
palemoon27/dom/bluetooth/common/ObexBase.h
T
roytam1 93f846cd1f import changes from `dev' branch of rmottola/Arctic-Fox:
- Bug 1275016 - Rename Endian.h to EndianUtils.h to avoid #include confusion with Android's endian.h stdlib header. r=froydnj (b54a25f572)
- add crashreporter stuff (aa7ef15337)
- Bug 1261168 - Add AlignedAutoTArray type in Web Audio; r=padenot (285d2cb88b)
- Bug 1273390. Part 1 - move some functions to private. r=jya. (07a3037e59)
- Bug 1273390. Part 2 - add assertions. r=jya. (2cae7c596a)
- Bug 1273390. Part 3 - rename some functions to be consistent with other sub-classes of MediaDataDecoder. r=jya. (c48c7060ce)
- Bug 1273390. Part 4 - remove use of FlushableTaskQueue::Flush(). r=jya. (00565a65f4)
- Bug 1273390. Part 5 - remove use of FlushableTaskQueue. r=jya. (30600b204e)
- Bug 1273774. Part 1 - remove unused members and thread assertions. r=jya (f5177ed641)
- Bug 1273774. Part 2 - do decoding jobs synchronously without dispatching. r=jya. (62d840d27c)
- Bug 1273774. Part 3 - remove members no longer used. r=jya. (e957ca512a)
- Bug 1244410: [ffmpeg] Ensure the last drained frame has the proper duration set. r=gerald (d5521bfdd4)
- Bug 1271508. Part 1 - refactor FFmpegAudioDecoder code to be similar to FFmpegVideoDecoder::Input() so it would be easier to extract common code to the parent class. r=jya. (613e6c624c)
- Bug 1271508. Part 2 - rename functions so they are the same as those of FFmpegAudioDecoder so it would be easier to extract common code to the parent class. r=jya. (cb281cba26)
- Bug 1270350 - per comment 0, use SyncRunnable to repalce the boilerplate code. r=jya. (b99460e571)
- Bug 1271508. Part 3 - extract code to the parent class and remove use of mTaskQueue from sub-classes. r=jya. (2a7ff4dd1e)
- Bug 1274216 - remove use of FlushableTaskQueue from PlatformDecoderModule. r=jya. (eb160c5fa2)
- Bug 1271517. Part 1 - remove use of FlushableTaskQueue::Flush() from FFmpegDataDecoder::Flush(). r=jya. (fdf10da4ab)
- Bug 1271517. Part 2 - remove use of FlushableTaskQueue. r=jya. (a7016d8506)
- Bug 1273397. Part 1 - rename some functions to be consistent with other MediaDataDecoder sub-classes. r=jya. (7eecb164be)
- Bug 1273397. Part 2 - constify some members. r=jya. (e4482f9a23)
- Bug 1273397. Part 3 - remove use of FlushableTaskQueue::Flush(). r=jya. (0b7ee073fe)
- Bug 1273397. Part 4 - remove use of FlushableTaskQueue. r=jya. (6a612161d5)
- Bug 1273397. Part 5 - add assertions. r=jya. (ff3a62a6fb)
- Bug 1274199 - remove use of FlushableTaskQueue. r=cpearce. (adc4c84ede)
- Bug 1273405. Part 1 - rename some functions to be consistent with other MediaDataDecoder sub-classes. r=jya. (af123d6c21)
- Bug 1273405. Part 2 - remove use of FlushableTaskQueue::Flush(). r=jya. (2d144bfbcd)
- Bug 1273405. Part 3 - remove use of FlushableTaskQueue. r=jya. (1e9ea3c2c7)
- Bug 1273405. Part 4 - add assertions. r=jya. (b400647323)
- Bug 1271491: [WMF] P1. Don't use main thread only preferences methods. r=cpearce (7177454dfb)
- Bug 1262427. Don't try D3D11 harder. r=dvander (404147d6fa)
- Use gfxConfig for D3D9 preferences. (bug 1270650, r=jrmuizel) (40d89c154c)
- Bug 1271491: P2. Allow initialization of WMFPlatformDecoderModule from any threads. r=mattwoodrow (c8fe0bf009)
- Bug 1271491: P3. Remove refcounting the number of time apple's linkers are called. r=cpearce (0324ffe876)
- Bug 1271491: [ffmpeg] P4. Remove requirements to call Init on the main thread. r=cpearce (b511d7dfd5)
- Bug 1271491: [GMP] P5. Allow GMPDecoderModule::Init() to be called off the main thread. r=cpearce (2131eb0b2e)
- Bug 1266102 - Don't run VP9 benchmark on Android r=jya (57d7b573fe)
- Bug 1271491: P6. Remove the need to call PDMFactory::Init(). r=cpearce (5726cfe49c)
- Bug 1271491: P7. Remove unused members. r=alfredo (0f8a9dde73)
- Bug 1268905 - Disable D3D11 with some Toshiba DLLs - r=cpearce (b5bf77442e)
- Bug 1269204 - Disable D3D11 with idg10umd32 9.17.10.2857 - r=cpearce (7eb6a3d96b)
- Bug 1273406 - Disable D3D11 with some iSonyVideoProcessor DLLs - r=cpearce (d9b6f0cefe)
- Bug 1273406 - Ugly macros transform into beautiful constexpr goodness - r=cpearce (0671483695)
- Bug 1273691 - Implement 'media.wmf.disable-d3d11-for-dlls' pref - r=cpearce (193ae53070)
- Bug 1272225. Part 1 - add assertions to make thread constraints clear. r=jya. (83c620470e)
- Bug 1272225. Part 2 - remove use of FlushableTaskQueue::Flush(). r=jya. (9473e092d1)
- Bug 1272553. Part 1 - move code around to be able to extract common code in P2. r=jya. (d727f97ee8)
- Bug 1272553. Part 2 - extract common code to the parent class. r=jya. (2fb3cd4bd9)
- Bug 1272553. Part 3 - make mTaskQueue private. r=jya. (93fea98cb6)
- Bug 1272232. Part 1 - move code around so we can extract common code in P2. r=jya. (8cdaab9078)
- Bug 1272232. Part 2 - extract common code to the parent class. r=jya. (27156668b3)
- Bug 1272232. Part 3 - constify some members and make them private when possible. r=jya. (550b963d97)
- Bug 1272232. Part 4 - remove use of FlushableTaskQueue::Flush(). r=jya. (bdbfdeb6bc)
- Bug 1272232. Part 5 - remove use of FlushableTaskQueue. r=jya. (640f889a9d)
- Bug 1274913 - Move PDM log definition to header. r=njn (823b07f42b)
- Bug 1275538: P1. Abort early if a skip request is in progress. r=gerald,kamidphish (d67b8a2236)
- Bug 1272422 - Part 1: Expose control of suspending background video. r=cpearce (ec7193773f)
- Bug 1272422 - Part 2: Vidoe -> Video. r=cpearce (97390aee69)
- Bug 1272422 - Part 3: Don't reset audio queue. r=jya (e183db1062)
- Bug 1272964: P1. Only activate skip to next keyframe logic when next keyframe time is known. r=gerald (1be74df027)
- Bug 1272964: P2. Don't activate skip to next keyframe until we passed the internal seek target. r=gerald (c55b6ae003)
- Bug 1258922: [MSE] P1. Initialise variable. r=gerald (56a5acb345)
- Bug 1258922: [MSE] P2. Do not go over gap when attempting to find the next key frame. r=gerald (db1319f080)
- Bug 1258922: [MSE] P3. Check that the data we are attempting to skip to is buffered. r=gerald (621d71d5d6)
- Bug 1258922: [MSE] P4. Set draining flag to true when skip to next keyframe failed. r=gerald (6c75613faf)
- Bug 1272916: [MSE] P1. Don't rely only on dts gap to establish if we have a gap in our source buffer. r=gerald (8770113b83)
- Bug 1272964: [MSE] P3. Do not skip over gaps when searching for the next keyframe. r=gerald (76916c5ac6)
- Bug 1272964: P4. Only flush decoder if skip to next keyframe actually succeeds. r=cpearce (5394708eef)
- Bug 1270323: P1. Don't reset flag indicating that new data was received. r=cpearce (d32f06ef34)
- Bug 1270323: P2. Don't process new incoming data while a skip to next keyframe is pending. r=cpearce (bca7909de9)
- Bug 1270323: [ffmpeg] P3. Use the dts of the last sample input, not the dts of the last decoded sample (0d768c33ef)
- Bug 1270323: P4. Don't drain decoder if we're already waiting for new data. r=cpearce (679302cb6e)
- Bug 1270323: P5. Prevent potential null deref. r=cpearce (cc63270e06)
- Bug 1275538: P2. Drop decoded frames that we know are already too late. r=kamidphish (4e7af9398c)
- Bug 1273018: P1. Rename some members. r=gerald (3a92fbd994)
- Bug 1273018: P2. Don't reject audio waiting promise when performing a video only seek. r=gerald (34e4988db1)
- Bug 1273018: P3. Adjust range of audio assertions. r=gerald (feb2afd0ae)
- Bug 1249706 - Backout a085ea2d24bb for blowing telemetry server's mind. r=backout (d61fb51f52)
- Bug 1249706 - Fix 8fe22dd4fc8a (backout of a085ea2d24bb). r=bustage (ba65251db7)
- Bug 1272964: [MSE] P5. Default to skipping to the next keyframe if no keyframe was found past currentTime. (29086fcf56)
- Bug 1272964: P6. Exclude frames dropped due to internal seeking from calculations. r=cpearce (bf6faa7612)
- Bug 1068151 - keep decoding a corrupted video. r=jya (3b5462e5b6)
- Bug 1273947 - Update ResetDecode() to ResetDecode(TargetQueue) r=jya (6c28d46974)
- Bug 1277508: P1. Don't attempt to demux new samples while we're currently draining. r=kamidphish (64f200b921)
- Bug 1274933: Reject data promise when EOS is encountered following waiting for data. r=gerald (5bba4a7853)
- Bug 1277508: P2. Add HasPendingDrain convenience method. r=kamidphish (3d89a90a97)
2024-10-08 23:23:56 +08:00

368 lines
9.4 KiB
C++

/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/. */
#ifndef mozilla_dom_bluetooth_ObexBase_h
#define mozilla_dom_bluetooth_ObexBase_h
#include "BluetoothCommon.h"
#include "mozilla/EndianUtils.h"
#include "mozilla/UniquePtr.h"
#include "nsTArray.h"
BEGIN_BLUETOOTH_NAMESPACE
const char FINAL_BIT = 0x80;
/**
* Section 3.2 "Response format", IrOBEX ver 1.2
* The format of an OBEX response header is
* [response code:1][response length:2]
*/
static const uint32_t kObexRespHeaderSize = 3;
/**
* Section 2.2.9 "Body, End-of-Body", IrOBEX ver 1.2
* The format of an OBEX Body header is
* [headerId:1][header length:2]
*/
static const uint32_t kObexBodyHeaderSize = 3;
/**
* Section 3.3.1.4 "Minimum OBEX Packet Length", IrOBEX ver 1.2
* The minimum size of the OBEX Maximum packet length allowed for negotiation is
* 255 bytes.
*/
static const uint32_t kObexLeastMaxSize = 255;
/*
* Defined in section 2.1 "OBEX Headers", IrOBEX ver 1.2
*/
enum ObexHeaderId {
Count = 0xC0,
Name = 0x01,
Type = 0x42,
Length = 0xC3,
TimeISO8601 = 0x44,
Time4Byte = 0xC4,
Description = 0x05,
Target = 0x46,
HTTP = 0x47,
Body = 0x48,
EndOfBody = 0x49,
Who = 0x4A,
ConnectionId = 0xCB,
AppParameters = 0x4C,
AuthChallenge = 0x4D,
AuthResponse = 0x4E,
ObjectClass = 0x4F
};
/*
* Defined in section 3.3 "OBEX Operations and Opcode definitions",
* IrOBEX ver 1.2
*/
enum ObexRequestCode {
Connect = 0x80,
Disconnect = 0x81,
Put = 0x02,
PutFinal = 0x82,
Get = 0x03,
GetFinal = 0x83,
SetPath = 0x85,
Abort = 0xFF
};
/*
* Defined in section 3.2.1 "Response Code values", IrOBEX ver 1.2
*/
enum ObexResponseCode {
Continue = 0x90,
Success = 0xA0,
Created = 0xA1,
Accepted = 0xA2,
NonAuthoritativeInfo = 0xA3,
NoContent = 0xA4,
ResetContent = 0xA5,
PartialContent = 0xA6,
MultipleChoices = 0xB0,
MovedPermanently = 0xB1,
MovedTemporarily = 0xB2,
SeeOther = 0xB3,
NotModified = 0xB4,
UseProxy = 0xB5,
BadRequest = 0xC0,
Unauthorized = 0xC1,
PaymentRequired = 0xC2,
Forbidden = 0xC3,
NotFound = 0xC4,
MethodNotAllowed = 0xC5,
NotAcceptable = 0xC6,
ProxyAuthenticationRequired = 0xC7,
RequestTimeOut = 0xC8,
Conflict = 0xC9,
Gone = 0xCA,
LengthRequired = 0xCB,
PreconditionFailed = 0xCC,
RequestedEntityTooLarge = 0xCD,
RequestUrlTooLarge = 0xCE,
UnsupprotedMediaType = 0xCF,
InternalServerError = 0xD0,
NotImplemented = 0xD1,
BadGateway = 0xD2,
ServiceUnavailable = 0xD3,
GatewayTimeout = 0xD4,
HttpVersionNotSupported = 0xD5,
DatabaseFull = 0xE0,
DatabaseLocked = 0xE1,
};
enum ObexDigestChallenge {
Nonce = 0x00,
Options = 0x01,
Realm = 0x02
};
enum ObexDigestResponse {
ReqDigest = 0x00,
UserId = 0x01,
NonceChallenged = 0x02
};
class ObexHeader
{
public:
ObexHeader(ObexHeaderId aId, int aDataLength, const uint8_t* aData)
: mId(aId)
, mDataLength(aDataLength)
, mData(nullptr)
{
mData.reset(new uint8_t[mDataLength]);
memcpy(mData.get(), aData, aDataLength);
}
~ObexHeader()
{
}
ObexHeaderId mId;
int mDataLength;
UniquePtr<uint8_t[]> mData;
};
class ObexHeaderSet
{
public:
ObexHeaderSet()
{
}
~ObexHeaderSet()
{
}
void AddHeader(ObexHeader* aHeader)
{
mHeaders.AppendElement(aHeader);
}
void GetName(nsString& aRetName) const
{
aRetName.Truncate();
int length = mHeaders.Length();
for (int i = 0; i < length; ++i) {
if (mHeaders[i]->mId == ObexHeaderId::Name) {
/*
* According to section 2.2.2 [Name] of IrOBEX spec, we know that
* the Name header is "a null terminated Unicode text string describing
* the name of the object.", and that's the reason why we need to minus
* 1 to get the real length of the file name.
*/
int nameLength = mHeaders[i]->mDataLength / 2 - 1;
uint8_t* ptr = mHeaders[i]->mData.get();
for (int j = 0; j < nameLength; ++j) {
char16_t c = BigEndian::readUint16(&ptr[j * 2]);
aRetName += c;
}
break;
}
}
}
void GetContentType(nsString& aRetContentType) const
{
aRetContentType.Truncate();
int length = mHeaders.Length();
for (int i = 0; i < length; ++i) {
if (mHeaders[i]->mId == ObexHeaderId::Type) {
uint8_t* ptr = mHeaders[i]->mData.get();
aRetContentType.AssignASCII((const char*)ptr);
break;
}
}
}
// @return file length, 0 means file length is unknown.
void GetLength(uint32_t* aRetLength) const
{
int length = mHeaders.Length();
*aRetLength = 0;
for (int i = 0; i < length; ++i) {
if (mHeaders[i]->mId == ObexHeaderId::Length) {
uint8_t* ptr = mHeaders[i]->mData.get();
*aRetLength = BigEndian::readUint32(&ptr[0]);
return;
}
}
}
void GetBody(uint8_t** aRetBody, int* aRetBodyLength) const
{
int length = mHeaders.Length();
*aRetBody = nullptr;
*aRetBodyLength = 0;
for (int i = 0; i < length; ++i) {
if (mHeaders[i]->mId == ObexHeaderId::Body ||
mHeaders[i]->mId == ObexHeaderId::EndOfBody) {
uint8_t* ptr = mHeaders[i]->mData.get();
*aRetBody = new uint8_t[mHeaders[i]->mDataLength];
memcpy(*aRetBody, ptr, mHeaders[i]->mDataLength);
*aRetBodyLength = mHeaders[i]->mDataLength;
return;
}
}
}
uint32_t GetConnectionId() const
{
int length = mHeaders.Length();
for (int i = 0; i < length; ++i) {
if (mHeaders[i]->mId == ObexHeaderId::ConnectionId) {
uint32_t* id = (uint32_t *) mHeaders[i]->mData.get();
return *id;
}
}
// According to OBEX spec., the value 0xFFFFFFFF is reserved and it's
// considered invalid for Connection ID.
return 0xFFFFFFFF;
}
/**
* Get a specified parameter from the 'Application Parameters' header with
* big-endian byte ordering.
*
* @param aTagId [in] The tag ID of parameter which is defined by
* applications or upper protocol layer.
* @param aRetBuf [out] The buffer which is used to return the parameter.
* @param aBufferSize [in] The size of the given buffer.
*
* @return a boolean value to indicate whether the given paramter exists.
*/
bool GetAppParameter(uint8_t aTagId, uint8_t* aRetBuf, int aBufferSize) const
{
int length = mHeaders.Length();
for (int i = 0; i < length; ++i) {
// Parse the 'Application Parameters' header.
if (mHeaders[i]->mId == ObexHeaderId::AppParameters) {
uint8_t* ptr = mHeaders[i]->mData.get();
int dataLen = mHeaders[i]->mDataLength;
// An application parameters header may contain more than one
// [tag]-[length]-[value] triplet. The [tag] and [length] fields are
// each one byte in length.
uint8_t tagId;
uint8_t offset = 0;
do {
tagId = *(ptr + offset++);
// The length of value field, it should not exceed 255.
uint8_t paramLen = *(ptr + offset++);
if (tagId == aTagId) {
memcpy(aRetBuf, ptr + offset, paramLen < aBufferSize ? paramLen
: aBufferSize);
return true;
}
offset += paramLen;
} while (offset < dataLen);
}
}
// The specified parameter don't exist in 'Application Parameters' header.
return false;
}
const ObexHeader* GetHeader(ObexHeaderId aId) const
{
for (int i = 0, length = mHeaders.Length(); i < length; ++i) {
if (mHeaders[i]->mId == aId) {
return mHeaders[i].get();
}
}
return nullptr;
}
bool Has(ObexHeaderId aId) const
{
return !!GetHeader(aId);
}
void ClearHeaders()
{
mHeaders.Clear();
}
private:
nsTArray<UniquePtr<ObexHeader> > mHeaders;
};
int AppendHeaderName(uint8_t* aRetBuf, int aBufferSize, const uint8_t* aName,
int aLength);
int AppendHeaderBody(uint8_t* aRetBuf, int aBufferSize, const uint8_t* aBody,
int aLength);
int AppendHeaderTarget(uint8_t* aRetBuf, int aBufferSize, const uint8_t* aTarget,
int aLength);
int AppendHeaderWho(uint8_t* aRetBuf, int aBufferSize, const uint8_t* aWho,
int aLength);
int AppendAuthResponse(uint8_t* aRetBuf, int aBufferSize,
const uint8_t* aDigest, int aLength);
int AppendHeaderAppParameters(uint8_t* aRetBuf, int aBufferSize,
const uint8_t* aAppParameters, int aLength);
int AppendAppParameter(uint8_t* aRetBuf, int aBufferSize, const uint8_t aTagId,
const uint8_t* aValue, int aLength);
int AppendHeaderLength(uint8_t* aRetBuf, int aObjectLength);
int AppendHeaderConnectionId(uint8_t* aRetBuf, int aConnectionId);
int AppendHeaderEndOfBody(uint8_t* aRetBuf);
void SetObexPacketInfo(uint8_t* aRetBuf, uint8_t aOpcode, int aPacketLength);
/**
* @return true when the message was parsed without any error, false otherwise.
*/
bool ParseHeaders(const uint8_t* aHeaderStart,
int aTotalLength,
ObexHeaderSet* aRetHanderSet);
END_BLUETOOTH_NAMESPACE
#endif // mozilla_dom_bluetooth_ObexBase_h